home *** CD-ROM | disk | FTP | other *** search
/ MacAddict 104 / MacAddict_104_2005-04.iso / Software / Internet & Communication / WordPress 1.2.2 freeware.dmg / wordpress / xmlrpc.php < prev   
Encoding:
PHP Script  |  2004-12-16  |  69.5 KB  |  2,340 lines

  1. <?php
  2.  
  3. # fix for mozBlog and other cases where '<?xml' isn't on the very first line
  4. $HTTP_RAW_POST_DATA = trim($HTTP_RAW_POST_DATA);
  5.  
  6. include('wp-config.php');
  7.  
  8. include_once (ABSPATH . WPINC . '/class-xmlrpc.php');
  9. include_once (ABSPATH . WPINC . '/class-xmlrpcs.php');
  10.  
  11. // Turn off all warnings and errors.
  12. error_reporting(0);
  13.  
  14. $post_default_title = ""; // posts submitted via the xmlrpc interface get that title
  15. $post_default_category = 1; // posts submitted via the xmlrpc interface go into that category
  16.  
  17. $xmlrpc_logging = 0;
  18.  
  19. function logIO($io,$msg) {
  20.     global $xmlrpc_logging;
  21.     if ($xmlrpc_logging) {
  22.         $fp = fopen("./xmlrpc.log","a+");
  23.         $date = gmdate("Y-m-d H:i:s ");
  24.         $iot = ($io == "I") ? " Input: " : " Output: ";
  25.         fwrite($fp, "\n\n".$date.$iot.$msg);
  26.         fclose($fp);
  27.     }
  28.     return true;
  29.     }
  30.  
  31. function starify($string) {
  32.     $i = strlen($string);
  33.     return str_repeat('*', $i);
  34. }
  35.  
  36. logIO("I", $HTTP_RAW_POST_DATA);
  37.  
  38. /**** DB Functions ****/
  39.  
  40. /*
  41.  * These really should be moved into wp-includes/functions.php,
  42.  * and re-used throughout the code, where possible. -- emc3
  43.  */
  44.  
  45. /*
  46.  * generic function for inserting data into the posts table.
  47.  */
  48. function wp_insert_post($postarr = array()) {
  49.     global $wpdb, $tableposts, $post_default_category;
  50.     
  51.     // export array as variables
  52.     extract($postarr);
  53.     
  54.     // Do some escapes for safety
  55.     $post_title = $wpdb->escape($post_title);
  56.     $post_name = sanitize_title($post_title);
  57.     $post_excerpt = $wpdb->escape($post_excerpt);
  58.     $post_content = $wpdb->escape($post_content);
  59.     $post_author = (int) $post_author;
  60.  
  61.     // Make sure we set a valid category
  62.     if (0 == count($post_category) || !is_array($post_category)) {
  63.         $post_category = array($post_default_category);
  64.     }
  65.  
  66.     $post_cat = $post_category[0];
  67.     
  68.     if (empty($post_date))
  69.         $post_date = current_time('mysql');
  70.     // Make sure we have a good gmt date:
  71.     if (empty($post_date_gmt)) 
  72.         $post_date_gmt = get_gmt_from_date($post_date);
  73.     
  74.     $sql = "INSERT INTO $tableposts 
  75.         (post_author, post_date, post_date_gmt, post_modified, post_modified_gmt, post_content, post_title, post_excerpt, post_category, post_status, post_name) 
  76.         VALUES ('$post_author', '$post_date', '$post_date_gmt', '$post_date', '$post_date_gmt', '$post_content', '$post_title', '$post_excerpt', '$post_cat', '$post_status', '$post_name')";
  77.     
  78.     $result = $wpdb->query($sql);
  79.     $post_ID = $wpdb->insert_id;
  80.     
  81.     wp_set_post_cats('',$post_ID,$post_category);
  82.     
  83.     // Return insert_id if we got a good result, otherwise return zero.
  84.     return $result ? $post_ID : 0;
  85. }
  86.  
  87. function wp_get_single_post($postid = 0, $mode = OBJECT) {
  88.     global $wpdb, $tableposts;
  89.  
  90.     $sql = "SELECT * FROM $tableposts WHERE ID=$postid";
  91.     $result = $wpdb->get_row($sql, $mode);
  92.     
  93.     // Set categories
  94.     $result['post_category'] = wp_get_post_cats('',$postid);
  95.  
  96.     return $result;
  97. }
  98.  
  99. function wp_get_recent_posts($num = 10) {
  100.     global $wpdb, $tableposts;
  101.  
  102.     // Set the limit clause, if we got a limit
  103.     if ($num) {
  104.         $limit = "LIMIT $num";
  105.     }
  106.  
  107.     $sql = "SELECT * FROM $tableposts ORDER BY post_date DESC $limit";
  108.     $result = $wpdb->get_results($sql,ARRAY_A);
  109.  
  110.     return $result?$result:array();
  111. }
  112.  
  113. function wp_update_post($postarr = array()) {
  114.     global $wpdb, $tableposts;
  115.  
  116.     // First get all of the original fields
  117.     extract(wp_get_single_post($postarr['ID'],ARRAY_A));    
  118.  
  119.     // Now overwrite any changed values being passed in
  120.     extract($postarr);
  121.     
  122.     // Make sure we set a valid category
  123.     if (0 == count($post_category) || !is_array($post_category)) {
  124.         $post_category = array($post_default_category);
  125.     }
  126.  
  127.     // Do some escapes for safety
  128.     $post_title = $wpdb->escape($post_title);
  129.     $post_excerpt = $wpdb->escape($post_excerpt);
  130.     $post_content = $wpdb->escape($post_content);
  131.  
  132.     $post_modified = current_time('mysql');
  133.     $post_modified_gmt = current_time('mysql', 1);
  134.  
  135.     $sql = "UPDATE $tableposts 
  136.         SET post_content = '$post_content',
  137.         post_title = '$post_title',
  138.         post_category = $post_category[0],
  139.         post_status = '$post_status',
  140.         post_date = '$post_date',
  141.         post_date_gmt = '$post_date_gmt',
  142.         post_modified = '$post_modified',
  143.         post_modified_gmt = '$post_modified_gmt',
  144.         post_excerpt = '$post_excerpt',
  145.         ping_status = '$ping_status',
  146.         comment_status = '$comment_status'
  147.         WHERE ID = $ID";
  148.         
  149.     $result = $wpdb->query($sql);
  150.  
  151.     wp_set_post_cats('',$ID,$post_category);
  152.     
  153.     return $wpdb->rows_affected;
  154. }
  155.  
  156. function wp_get_post_cats($blogid = '1', $post_ID = 0) {
  157.     global $wpdb, $tablepost2cat;
  158.     
  159.     $sql = "SELECT category_id 
  160.         FROM $tablepost2cat 
  161.         WHERE post_id = $post_ID 
  162.         ORDER BY category_id";
  163.  
  164.     $result = $wpdb->get_col($sql);
  165.  
  166.     return array_unique($result);
  167. }
  168.  
  169. function wp_set_post_cats($blogid = '1', $post_ID = 0, $post_categories = array()) {
  170.     global $wpdb, $tablepost2cat;
  171.     // If $post_categories isn't already an array, make it one:
  172.     if (!is_array($post_categories)) {
  173.         if (!$post_categories) {
  174.             $post_categories = 1;
  175.         }
  176.         $post_categories = array($post_categories);
  177.     }
  178.  
  179.     $post_categories = array_unique($post_categories);
  180.  
  181.     // First the old categories
  182.     $old_categories = $wpdb->get_col("
  183.         SELECT category_id 
  184.         FROM $tablepost2cat 
  185.         WHERE post_id = $post_ID");
  186.     
  187.     if (!$old_categories) {
  188.         $old_categories = array();
  189.     } else {
  190.         $old_categories = array_unique($old_categories);
  191.     }
  192.  
  193.  
  194.     $oldies = print_r($old_categories,1);
  195.     $newbies = print_r($post_categories,1);
  196.  
  197.     logio("O","Old: $oldies\nNew: $newbies\n");
  198.  
  199.     // Delete any?
  200.     $delete_cats = array_diff($old_categories,$post_categories);
  201.  
  202.     logio("O","Delete: " . print_r($delete_cats,1));
  203.         
  204.     if ($delete_cats) {
  205.         foreach ($delete_cats as $del) {
  206.             $wpdb->query("
  207.                 DELETE FROM $tablepost2cat 
  208.                 WHERE category_id = $del 
  209.                     AND post_id = $post_ID 
  210.                 ");
  211.  
  212.             logio("O","deleting post/cat: $post_ID, $del");
  213.         }
  214.     }
  215.  
  216.     // Add any?
  217.     $add_cats = array_diff($post_categories, $old_categories);
  218.  
  219.     logio("O","Add: " . print_r($add_cats,1));
  220.         
  221.     if ($add_cats) {
  222.         foreach ($add_cats as $new_cat) {
  223.             $wpdb->query("
  224.                 INSERT INTO $tablepost2cat (post_id, category_id) 
  225.                 VALUES ($post_ID, $new_cat)");
  226.  
  227.                 logio("O","adding post/cat: $post_ID, $new_cat");
  228.         }
  229.     }
  230. }    // wp_set_post_cats()
  231.  
  232. function wp_delete_post($postid = 0) {
  233.     global $wpdb, $tableposts, $tablepost2cat;
  234.     
  235.     $sql = "DELETE FROM $tablepost2cat WHERE post_id = $postid";
  236.     $wpdb->query($sql);
  237.         
  238.     $sql = "DELETE FROM $tableposts WHERE ID = $postid";
  239.     
  240.     $wpdb->query($sql);
  241.  
  242.     $result = $wpdb->rows_affected;
  243.     
  244.     return $result;
  245. }
  246.  
  247. /**** /DB Functions ****/
  248.  
  249. /**** Misc ****/
  250.  
  251. // get permalink from post ID
  252. function post_permalink($post_ID=0, $mode = 'id') {
  253.     global $wpdb;
  254.     global $tableposts;
  255.     global $querystring_start, $querystring_equal, $querystring_separator;
  256.  
  257.     $blog_URL = get_settings('home') .'/'. get_settings('blogfilename');
  258.  
  259.     $postdata = get_postdata($post_ID);
  260.  
  261.     // this will probably change to $blog_ID = $postdata['Blog_ID'] one day.
  262.     $blog_ID = 1;
  263.  
  264.     if (!($postdata===false)) {
  265.     
  266.         switch(strtolower($mode)) {
  267.             case 'title':
  268.                 $title = preg_replace('/[^a-zA-Z0-9_\.-]/', '_', $postdata['Title']);
  269.                 break;
  270.             case 'id':
  271.             default:
  272.                 $title = "post-$post_ID";
  273.                 break;
  274.         }
  275.  
  276.         // this code is blatantly derived from permalink_link()
  277.         $archive_mode = get_settings('archive_mode');
  278.         switch($archive_mode) {
  279.             case 'daily':
  280.                 $post_URL = $blog_URL.$querystring_start.'m'.$querystring_equal.substr($postdata['Date'],0,4).substr($postdata['Date'],5,2).substr($postdata['Date'],8,2).'#'.$title;
  281.                 break;
  282.             case 'monthly':
  283.                 $post_URL = $blog_URL.$querystring_start.'m'.$querystring_equal.substr($postdata['Date'],0,4).substr($postdata['Date'],5,2).'#'.$title;
  284.                 break;
  285.             case 'weekly':
  286.                 if((!isset($cacheweekly)) || (empty($cacheweekly[$postdata['Date']]))) {
  287.                     $sql = "SELECT WEEK('".$postdata['Date']."') as wk";
  288.                         $row = $wpdb->get_row($sql);
  289.                     $cacheweekly[$postdata['Date']] = $row->wk;
  290.                 }
  291.                 $post_URL = $blog_URL.$querystring_start.'m'.$querystring_equal.substr($postdata['Date'],0,4).$querystring_separator.'w'.$querystring_equal.$cacheweekly[$postdata['Date']].'#'.$title;
  292.                 break;
  293.             case 'postbypost':
  294.                 $post_URL = $blog_URL.$querystring_start.'p'.$querystring_equal.$post_ID;
  295.                 break;
  296.         }
  297.     } 
  298.  
  299.     return $post_URL;
  300. }
  301.  
  302. // Get the name of a category from its ID
  303. function get_cat_name($cat_id) {
  304.     global $wpdb,$tablecategories;
  305.     
  306.     $cat_id -= 0;     // force numeric
  307.     $name = $wpdb->get_var("SELECT cat_name FROM $tablecategories WHERE cat_ID=$cat_id");
  308.     
  309.     return $name;
  310. }
  311.  
  312. // Get the ID of a category from its name
  313. function get_cat_ID($cat_name='General') {
  314.     global $wpdb,$tablecategories;
  315.     
  316.     $cid = $wpdb->get_var("SELECT cat_ID FROM $tablecategories WHERE cat_name='$cat_name'");
  317.  
  318.     return $cid?$cid:1;    // default to cat 1
  319. }
  320.  
  321. // Get author's preferred display name
  322. function get_author_name($auth_id) {
  323.     $authordata = get_userdata($auth_id);
  324.  
  325.     switch($authordata["user_idmode"]) {
  326.         case "nickname":
  327.             $authorname = $authordata["user_nickname"];
  328.  
  329.         case "login":
  330.             $authorname = $authordata["user_login"];
  331.             break;
  332.     
  333.         case "firstname":
  334.             $authorname = $authordata["user_firstname"];
  335.             break;
  336.  
  337.         case "lastname":
  338.             $authorname = $authordata["user_lastname"];
  339.             break;
  340.  
  341.         case "namefl":
  342.             $authorname = $authordata["user_firstname"]." ".$authordata["user_lastname"];
  343.             break;
  344.  
  345.         case "namelf":
  346.             $authorname = $authordata["user_lastname"]." ".$authordata["user_firstname"];
  347.             break;
  348.  
  349.         default:
  350.             $authorname = $authordata["user_nickname"];
  351.             break;
  352.     }
  353.  
  354.     return $authorname;
  355. }
  356.  
  357. // get extended entry info (<!--more-->)
  358. function get_extended($post) {
  359.     list($main,$extended) = explode('<!--more-->',$post);
  360.  
  361.     // Strip leading and trailing whitespace
  362.     $main = preg_replace('/^[\s]*(.*)[\s]*$/','\\1',$main);
  363.     $extended = preg_replace('/^[\s]*(.*)[\s]*$/','\\1',$extended);
  364.  
  365.     return array('main' => $main, 'extended' => $extended);
  366. }
  367.  
  368. // do trackbacks for a list of urls
  369. // borrowed from edit.php
  370. // accepts a comma-separated list of trackback urls and a post id
  371. function trackback_url_list($tb_list, $post_id) {
  372.     if (!empty($tb_list)) {
  373.         // get post data
  374.         $postdata = wp_get_single_post($post_id, ARRAY_A);
  375.  
  376.         // import postdata as variables
  377.         extract($postdata);
  378.         
  379.         // form an excerpt
  380.         $excerpt = strip_tags($post_excerpt?$post_excerpt:$post_content);
  381.         
  382.         if (strlen($excerpt) > 255) {
  383.             $exerpt = substr($excerpt,0,252) . '...';
  384.         }
  385.         
  386.         $trackback_urls = explode(',', $tb_list);
  387.         foreach($trackback_urls as $tb_url) {
  388.             $tb_url = trim($tb_url);
  389.             trackback($tb_url, stripslashes($post_title), $excerpt, $post_id);
  390.         }
  391.     }
  392. }
  393.  
  394. /**** /Misc ****/
  395.  
  396. /**** B2 API ****/
  397.  
  398.  
  399. # note: the b2 API currently consists of the Blogger API,
  400. #       plus the following methods:
  401. #
  402. # b2.newPost , b2.getCategories
  403.  
  404. # Note: the b2 API will be replaced by the standard Weblogs.API once the specs are defined.
  405.  
  406.  
  407. ### b2.newPost ###
  408.  
  409. $wpnewpost_sig=array(array($xmlrpcString, $xmlrpcString, $xmlrpcString, $xmlrpcString, $xmlrpcString, $xmlrpcString, $xmlrpcBoolean, $xmlrpcString, $xmlrpcString, $xmlrpcString));
  410.  
  411. $wpnewpost_doc='Adds a post, blogger-api like, +title +category +postdate';
  412.  
  413. function b2newpost($m) {
  414.     global $wpdb;
  415.  
  416.     global $xmlrpcerruser; // import user errcode value
  417.     global $blog_ID,$cache_userdata,$tableposts,$use_rss;
  418.     global $post_default_title,$post_default_category;
  419.     global $cafelogID, $sleep_after_edit;
  420.     $err="";
  421.  
  422.  
  423.     $username=$m->getParam(2);
  424.     $password=$m->getParam(3);
  425.     $content=$m->getParam(4);
  426.     $title=$m->getParam(6);
  427.     $category=$m->getParam(7);
  428.     $postdate=$m->getParam(8);
  429.  
  430.     $username = $username->scalarval();
  431.     $password = $password->scalarval();
  432.     $content = $content->scalarval();
  433.     $title = $title->scalarval();
  434.     $post_category = $category->scalarval();
  435.     $postdate = $postdate->scalarval();
  436.  
  437.  
  438.     if (user_pass_ok($username,$password)) {
  439.  
  440.         $userdata = get_userdatabylogin($username);
  441.         $post_author = $userdata->ID;
  442.         $user_level = $userdata->user_level;
  443.         if ($user_level < 1) {
  444.             return new xmlrpcresp(0, $xmlrpcerruser+1, // user error 1
  445.        "Sorry, level 0 users can not post");
  446.         }
  447.  
  448.  
  449.         $post_content = format_to_post($content);
  450.         $post_title = addslashes($title);
  451.  
  452.  
  453.         if ($postdate != "") {
  454.             $post_date = $postdate;
  455.             $post_date_gmt = get_gmt_from_date($postdate);
  456.         } else {
  457.             $post_date = current_time('mysql');
  458.             $post_date_gmt = current_time('mysql', 1);
  459.         }
  460.  
  461.         $post_data = compact('post_content','post_title','post_date','post_date_gmt','post_author','post_category');
  462.         
  463.         $result = wp_insert_post($post_data);
  464.  
  465.         if (!$result)
  466.             return new xmlrpcresp(0, $xmlrpcerruser+2, // user error 2
  467.        "For some strange yet very annoying reason, your entry couldn't be posted.");
  468.  
  469.  
  470.         $post_ID = $result;
  471.  
  472.         if (!isset($blog_ID)) { $blog_ID = 1; }
  473.         
  474.         if (isset($sleep_after_edit) && $sleep_after_edit > 0) {
  475.             sleep($sleep_after_edit);
  476.         }
  477.  
  478.  
  479.  
  480.         pingback($content, $post_ID);
  481.  
  482.  
  483.         return new xmlrpcresp(new xmlrpcval("$post_ID"));
  484.  
  485.     } else {
  486.  
  487.         return new xmlrpcresp(0, $xmlrpcerruser+3, // user error 3
  488.        'Wrong username/password combination '.$username.' / '.starify($password));
  489.     }
  490. }
  491.  
  492.  
  493.  
  494. ### b2.getCategories ###
  495.  
  496. $wpgetcategories_sig=array(array($xmlrpcString, $xmlrpcString, $xmlrpcString, $xmlrpcString));
  497.  
  498. $wpgetcategories_doc='given a blogID, gives a struct that list categories in that blog, using categoryID and categoryName. categoryName is there so the user would choose a category name from the client, rather than just a number. however, when using b2.newPost, only the category ID number should be sent.';
  499.  
  500. function b2getcategories($m) {
  501.     global $wpdb;
  502.     global $xmlrpcerruser,$tablecategories;
  503.  
  504.  
  505.     $blogid=$m->getParam(0);
  506.     $blogid = $blogid->scalarval(); // we dot not use that yet, that will be used with multiple blogs
  507.  
  508.     $username=$m->getParam(1);
  509.     $username = $username->scalarval();
  510.  
  511.     $password=$m->getParam(2);
  512.     $password = $password->scalarval();
  513.  
  514.     $userdata = get_userdatabylogin($username);
  515.  
  516.  
  517.     if (user_pass_ok($username,$password)) {
  518.  
  519.         $results = $wpdb->get_results("SELECT * FROM $tablecategories ORDER BY cat_ID ASC");
  520.     if (!$results) die("Error getting data");
  521.         $i = 0;
  522.     foreach($results as $row) {
  523.             $cat_name = $row->cat_name;
  524.             $cat_ID = $row->cat_ID;
  525.  
  526.             $struct[$i] = new xmlrpcval(array("categoryID" => new xmlrpcval($cat_ID),
  527.                                           "categoryName" => new xmlrpcval($cat_name)
  528.                                           ),"struct");
  529.             $i = $i + 1;
  530.         }
  531.  
  532.         $data = array($struct[0]);
  533.         for ($j=1; $j<$i; $j++) {
  534.             array_push($data, $struct[$j]);
  535.         }
  536.  
  537.         $resp = new xmlrpcval($data, "array");
  538.  
  539.         return new xmlrpcresp($resp);
  540.  
  541.     } else {
  542.         return new xmlrpcresp(0, $xmlrpcerruser+3, // user error 3
  543.        'Wrong username/password combination '.$username.' / '.starify($password));
  544.     }
  545. }
  546.  
  547.  
  548.  
  549. ### b2.getPostURL ###
  550.  
  551. $wp_getPostURL_sig = array(array($xmlrpcString, $xmlrpcString, $xmlrpcString, $xmlrpcString, $xmlrpcString, $xmlrpcString));
  552.  
  553. $wp_getPostURL_doc = 'Given a blog ID, username, password, and a post ID, returns the URL to that post.';
  554.  
  555. function b2_getPostURL($m) {
  556.     global $wpdb;
  557.     global $xmlrpcerruser, $tableposts;
  558.     global $querystring_start, $querystring_equal, $querystring_separator;
  559.  
  560.  
  561.     // ideally, this would be used:
  562.     // $blog_ID = $m->getParam(0);
  563.     // $blog_ID = $blog_ID->scalarval();
  564.     // but right now, b2 handles only one blog, so... :P
  565.     $blog_ID = 1;
  566.  
  567.     $username=$m->getParam(2);
  568.     $username = $username->scalarval();
  569.  
  570.     $password=$m->getParam(3);
  571.     $password = $password->scalarval();
  572.  
  573.     $post_ID = $m->getParam(4);
  574.     $post_ID = intval($post_ID->scalarval());
  575.  
  576.     $userdata = get_userdatabylogin($username);
  577.  
  578.     if ($userdata->user_level < 1) {
  579.         return new xmlrpcresp(0, $xmlrpcerruser+1, // user error 1
  580.        "Sorry, users whose level is zero, can not use this method.");
  581.     }
  582.  
  583.     if (user_pass_ok($username,$password)) {
  584.  
  585.         $blog_URL = get_settings('home') .'/' . get_settings('blogfilename');
  586.  
  587.         $postdata = get_postdata($post_ID);
  588.  
  589.         if (!($postdata===false)) {
  590.  
  591.             $title = preg_replace('/[^a-zA-Z0-9_\.-]/', '_', $postdata['Title']);
  592.  
  593.             // this code is blatantly derived from permalink_link()
  594.             $archive_mode = get_settings('archive_mode');
  595.             switch($archive_mode) {
  596.                 case 'daily':
  597.                     $post_URL = $blog_URL.$querystring_start.'m'.$querystring_equal.substr($postdata['Date'],0,4).substr($postdata['Date'],5,2).substr($postdata['Date'],8,2).'#'.$title;
  598.                     break;
  599.                 case 'monthly':
  600.                     $post_URL = $blog_URL.$querystring_start.'m'.$querystring_equal.substr($postdata['Date'],0,4).substr($postdata['Date'],5,2).'#'.$title;
  601.                     break;
  602.                 case 'weekly':
  603.                     if((!isset($cacheweekly)) || (empty($cacheweekly[$postdata['Date']]))) {
  604.                         $sql = "SELECT WEEK('".$postdata['Date']."') as wk";
  605.             $row = $wpdb->get_row($sql);
  606.                         $cacheweekly[$postdata['Date']] = $row->wk;
  607.                     }
  608.                     $post_URL = $blog_URL.$querystring_start.'m'.$querystring_equal.substr($postdata['Date'],0,4).$querystring_separator.'w'.$querystring_equal.$cacheweekly[$postdata['Date']].'#'.$title;
  609.                     break;
  610.                 case 'postbypost':
  611.                     $post_URL = $blog_URL.$querystring_start.'p'.$querystring_equal.$post_ID;
  612.                     break;
  613.             }
  614.         } else {
  615.             $err = 'This post ID ('.$post_ID.') does not correspond to any post here.';
  616.         }
  617.  
  618.         if ($err) {
  619.             return new xmlrpcresp(0, $xmlrpcerruser, $err);
  620.         } else {
  621.             return new xmlrpcresp(new xmlrpcval($post_URL));;
  622.         }
  623.  
  624.     } else {
  625.         return new xmlrpcresp(0, $xmlrpcerruser+3, // user error 3
  626.        'Wrong username/password combination '.$username.' / '.starify($password));
  627.     }
  628.  
  629. }
  630.  
  631. /**** /B2 API ****/
  632.  
  633.  
  634.  
  635. /**** Blogger API ****/
  636.  
  637. # as described on http://plant.blogger.com/api and in various messages in http://groups.yahoo.com/group/bloggerDev/
  638. #
  639. # another list of these methods is there http://www.tswoam.co.uk/blogger_method_listing.html
  640. # so you won't have to browse the eGroup to find all the methods
  641. #
  642. # special note: Evan please keep _your_ API page up to date :p
  643.  
  644.  
  645.  
  646. ### blogger.newPost ###
  647.  
  648. $bloggernewpost_sig=array(array($xmlrpcString, $xmlrpcString, $xmlrpcString, $xmlrpcString, $xmlrpcString, $xmlrpcString, $xmlrpcBoolean));
  649.  
  650. $bloggernewpost_doc='Adds a post, blogger-api like';
  651.  
  652. function bloggernewpost($m) {
  653.     global $wpdb;
  654.  
  655.     global $xmlrpcerruser; // import user errcode value
  656.     global $blog_ID,$cache_userdata,$tableposts,$use_rss;
  657.     global $post_default_title,$post_default_category;
  658.     global $cafelogID, $sleep_after_edit;
  659.     $err="";
  660.  
  661.  
  662.     $username=$m->getParam(2);
  663.     $password=$m->getParam(3);
  664.     $content=$m->getParam(4);
  665.     $publish=$m->getParam(5);
  666.  
  667.     $username = $username->scalarval();
  668.     $password = $password->scalarval();
  669.     $content = $content->scalarval();
  670.     // publish flag sets post status appropriately
  671.     $post_status = $publish->scalarval()?'publish':'draft';
  672.     
  673.     if (user_pass_ok($username,$password)) {
  674.  
  675.         $userdata = get_userdatabylogin($username);
  676.         $post_author = $userdata->ID;
  677.         $user_level = $userdata->user_level;
  678.         if ($user_level < 1) {
  679.             return new xmlrpcresp(0, $xmlrpcerruser+1, // user error 1
  680.        "Sorry, level 0 users can not post");
  681.         }
  682.  
  683.         $post_title = addslashes(xmlrpc_getposttitle($content));
  684.         $post_category = xmlrpc_getpostcategory($content);
  685.  
  686.         $content = xmlrpc_removepostdata($content);
  687.         $post_content = format_to_post($content);
  688.  
  689.         $post_date = current_time('mysql');
  690.         $post_date_gmt = current_time('mysql', 1);
  691.         
  692.         $postdata = compact('post_author', 'post_date', 'post_date_gmt', 'post_content', 'post_title', 'post_category', 'post_status');
  693.  
  694.         $post_ID = wp_insert_post($postdata);
  695.  
  696.         if (!$post_ID)
  697.             return new xmlrpcresp(0, $xmlrpcerruser+2, // user error 2
  698.        "For some strange yet very annoying reason, your entry couldn't be posted.");
  699.  
  700.         if (!isset($blog_ID)) { $blog_ID = 1; }
  701.         
  702.         if (isset($sleep_after_edit) && $sleep_after_edit > 0) {
  703.             sleep($sleep_after_edit);
  704.         }
  705.  
  706.  
  707.         pingback($content, $post_ID);
  708.  
  709.         logIO("O","Posted ! ID: $post_ID");
  710.         return new xmlrpcresp(new xmlrpcval("$post_ID"));
  711.  
  712.     } else {
  713.         logIO("O","Wrong username/password combination <b>$username / $password</b>");
  714.         return new xmlrpcresp(0, $xmlrpcerruser+3, // user error 3
  715.        'Wrong username/password combination '.$username.' / '.starify($password));
  716.     }
  717. }
  718.  
  719.  
  720.  
  721. ### blogger.editPost ###
  722.  
  723. $bloggereditpost_sig=array(array($xmlrpcBoolean, $xmlrpcString, $xmlrpcString, $xmlrpcString, $xmlrpcString, $xmlrpcString, $xmlrpcBoolean));
  724.  
  725. $bloggereditpost_doc='Edits a post, blogger-api like';
  726.  
  727. function bloggereditpost($m) {
  728.     global $wpdb;
  729.  
  730.     global $xmlrpcerruser; // import user errcode value
  731.     global $blog_ID,$cache_userdata,$tableposts,$use_rss;
  732.     global $post_default_title,$post_default_category, $sleep_after_edit;
  733.     $err="";
  734.  
  735.  
  736.     $post_ID=$m->getParam(1);
  737.     $username=$m->getParam(2);
  738.     $password=$m->getParam(3);
  739.     $newcontent=$m->getParam(4);
  740.     $publish=$m->getParam(5);
  741.  
  742.     $ID = $post_ID->scalarval();
  743.     $username = $username->scalarval();
  744.     $password = $password->scalarval();
  745.     $newcontent = $newcontent->scalarval();
  746.     $post_status = $publish->scalarval()?'publish':'draft';
  747.  
  748.     $result = wp_get_single_post($ID,ARRAY_A);
  749.  
  750.     if (!$result)
  751.         return new xmlrpcresp(0, $xmlrpcerruser+2, // user error 2
  752.       "No such post '$ID'.");
  753.  
  754.     $userdata = get_userdatabylogin($username);
  755.     $user_ID = $userdata->ID;
  756.     $user_level = $userdata->user_level;
  757.  
  758.     $postdata=get_postdata($ID);
  759.     $post_authordata=get_userdata($postdata["Author_ID"]);
  760.     $post_author_ID=$postdata["Author_ID"];
  761.  
  762.     if (($user_ID != $post_author_ID) && ($user_level <= $post_authordata->user_level)) {
  763.             return new xmlrpcresp(0, $xmlrpcerruser+1, // user error 1
  764.        "Sorry, you do not have the right to edit this post");
  765.     }
  766.  
  767.     if (user_pass_ok($username,$password)) {
  768.  
  769.         if ($user_level < 1) {
  770.             return new xmlrpcresp(0, $xmlrpcerruser+1, // user error 1
  771.        "Sorry, level 0 users can not edit posts");
  772.         }
  773.         
  774.         extract($result);
  775.  
  776.         $content = $newcontent;
  777.  
  778.         $post_title = xmlrpc_getposttitle($content);
  779.         $post_category = xmlrpc_getpostcategory($content);
  780.  
  781.         $content = xmlrpc_removepostdata($content);
  782.         $post_content = format_to_post($content);
  783.         
  784.         $postdata = compact('ID','post_content','post_title','post_category','post_status','post_excerpt');
  785.  
  786.         $result = wp_update_post($postdata);
  787.  
  788.         if (!$result)
  789.             return new xmlrpcresp(0, $xmlrpcerruser+2, // user error 2
  790.        "For some strange yet very annoying reason, the entry couldn't be edited.");
  791.  
  792.         if (!isset($blog_ID)) { $blog_ID = 1; }
  793.         
  794.         if (isset($sleep_after_edit) && $sleep_after_edit > 0) {
  795.             sleep($sleep_after_edit);
  796.         }
  797.  
  798.  
  799.  
  800.         return new xmlrpcresp(new xmlrpcval(true, "boolean"));
  801.  
  802.     } else {
  803.         return new xmlrpcresp(0, $xmlrpcerruser+3, // user error 3
  804.        'Wrong username/password combination '.$username.' / '.starify($password));
  805.     }
  806. }
  807.  
  808.  
  809.  
  810. ### blogger.deletePost ###
  811.  
  812. $bloggerdeletepost_sig=array(array($xmlrpcBoolean, $xmlrpcString, $xmlrpcString, $xmlrpcString, $xmlrpcString, $xmlrpcBoolean));
  813.  
  814. $bloggerdeletepost_doc='Deletes a post, blogger-api like';
  815.  
  816. function bloggerdeletepost($m) {
  817.     global $wpdb;
  818.  
  819.     global $xmlrpcerruser; // import user errcode value
  820.     global $blog_ID,$cache_userdata,$tableposts,$use_rss;
  821.     global $post_default_title,$post_default_category, $sleep_after_edit;
  822.     $err="";
  823.  
  824.  
  825.     $post_ID=$m->getParam(1);
  826.     $username=$m->getParam(2);
  827.     $password=$m->getParam(3);
  828.     $newcontent=$m->getParam(4);
  829.  
  830.     $post_ID = $post_ID->scalarval();
  831.     $username = $username->scalarval();
  832.     $password = $password->scalarval();
  833.     $newcontent = $newcontent->scalarval();
  834.  
  835.     $sql = "SELECT * FROM $tableposts WHERE ID = '$post_ID'";
  836.     $result = $wpdb->get_results($sql);
  837.     if (!$result)
  838.         return new xmlrpcresp(0, $xmlrpcerruser+2, // user error 2
  839.       "No such post '$post_ID'.");
  840.  
  841.     $userdata = get_userdatabylogin($username);
  842.     $user_ID = $userdata->ID;
  843.     $user_level = $userdata->user_level;
  844.  
  845.     $postdata=get_postdata($post_ID);
  846.     $post_authordata=get_userdata($postdata["Author_ID"]);
  847.     $post_author_ID=$postdata["Author_ID"];
  848.  
  849.     if (($user_ID != $post_author_ID) && ($user_level <= $post_authordata->user_level)) {
  850.             return new xmlrpcresp(0, $xmlrpcerruser+1, // user error 1
  851.        "Sorry, you do not have the right to delete this post");
  852.     }
  853.  
  854.     if (user_pass_ok($username,$password)) {
  855.  
  856.         if ($user_level < 1) {
  857.             return new xmlrpcresp(0, $xmlrpcerruser+1, // user error 1
  858.        "Sorry, level 0 users can not delete posts");
  859.         }
  860.  
  861.         $result = wp_delete_post($post_ID);
  862.  
  863.         if (!$result)
  864.             return new xmlrpcresp(0, $xmlrpcerruser+2, // user error 2
  865.        "For some strange yet very annoying reason, the entry couldn't be deleted.");
  866.  
  867.         if (!isset($blog_ID)) { $blog_ID = 1; }
  868.         
  869.         if (isset($sleep_after_edit) && $sleep_after_edit > 0) {
  870.             sleep($sleep_after_edit);
  871.         }
  872.  
  873.  
  874.  
  875.         return new xmlrpcresp(new xmlrpcval(true,'boolean'));
  876.  
  877.     } else {
  878.         return new xmlrpcresp(0, $xmlrpcerruser+3, // user error 3
  879.        'Wrong username/password combination '.$username.' / '.starify($password));
  880.     }
  881. }
  882.  
  883.  
  884.  
  885. ### blogger.getUsersBlogs ###
  886.  
  887. $bloggergetusersblogs_sig=array(array($xmlrpcArray, $xmlrpcString, $xmlrpcString, $xmlrpcString));
  888.  
  889. $bloggergetusersblogs_doc='returns the user\'s blogs - this is a dummy function, just so that BlogBuddy and other blogs-retrieving apps work';
  890.  
  891. function bloggergetusersblogs($m) {
  892.     global $wpdb;
  893.     // this function will have a real purpose with CafeLog's multiple blogs capability
  894.  
  895.     global $xmlrpcerruser;
  896.     global $tableusers;
  897.  
  898.     $user_login = $m->getParam(1);
  899.     $user_login = $user_login->scalarval();
  900.  
  901.  
  902.     $sql = "SELECT user_level FROM $tableusers WHERE user_login = '$user_login' AND user_level > 3";
  903.     $result = $wpdb->get_results($sql);
  904.  
  905.  
  906.     $is_admin = $wpdb->num_rows;
  907.  
  908.     $struct = new xmlrpcval(array("isAdmin" => new xmlrpcval($is_admin,"boolean"),
  909.                                     "url" => new xmlrpcval(get_settings('home') .'/'.get_settings('blogfilename')),
  910.                                     "blogid" => new xmlrpcval("1"),
  911.                                     "blogName" => new xmlrpcval(get_settings('blogname'))
  912.                                     ),"struct");
  913.     $resp = new xmlrpcval(array($struct), "array");
  914.  
  915.     return new xmlrpcresp($resp);
  916. }
  917.  
  918.  
  919.  
  920. ### blogger.getUserInfo ###
  921.  
  922. $bloggergetuserinfo_sig=array(array($xmlrpcStruct, $xmlrpcString, $xmlrpcString, $xmlrpcString));
  923.  
  924. $bloggergetuserinfo_doc='gives the info about a user';
  925.  
  926. function bloggergetuserinfo($m) {
  927.     global $xmlrpcerruser,$tableusers;
  928.  
  929.  
  930.     $username=$m->getParam(1);
  931.     $username = $username->scalarval();
  932.  
  933.     $password=$m->getParam(2);
  934.     $password = $password->scalarval();
  935.  
  936.     $userdata = get_userdatabylogin($username);
  937.  
  938.     if (user_pass_ok($username,$password)) {
  939.         $struct = new xmlrpcval(array("nickname" => new xmlrpcval($userdata->user_nickname),
  940.                                       "userid" => new xmlrpcval($userdata->ID),
  941.                                       "url" => new xmlrpcval($userdata->user_url),
  942.                                       "email" => new xmlrpcval($userdata->user_email),
  943.                                       "lastname" => new xmlrpcval($userdata->user_lastname),
  944.                                       "firstname" => new xmlrpcval($userdata->user_firstname)
  945.                                       ),"struct");
  946.         $resp = $struct;
  947.         return new xmlrpcresp($resp);
  948.  
  949.     } else {
  950.         return new xmlrpcresp(0, $xmlrpcerruser+3, // user error 3
  951.        'Wrong username/password combination '.$username.' / '.starify($password));
  952.     }
  953. }
  954.  
  955.  
  956.  
  957. ### blogger.getPost ###
  958.  
  959. $bloggergetpost_sig=array(array($xmlrpcStruct, $xmlrpcString, $xmlrpcString, $xmlrpcString, $xmlrpcString));
  960.  
  961. $bloggergetpost_doc='fetches a post, blogger-api like';
  962.  
  963. function bloggergetpost($m) {
  964.     global $xmlrpcerruser,$tableposts;
  965.  
  966.  
  967.     $post_ID=$m->getParam(1);
  968.     $post_ID = $post_ID->scalarval();
  969.  
  970.     $username=$m->getParam(2);
  971.     $username = $username->scalarval();
  972.  
  973.     $password=$m->getParam(3);
  974.     $password = $password->scalarval();
  975.  
  976.     if (user_pass_ok($username,$password)) {
  977.         $postdata = get_postdata($post_ID);
  978.  
  979.         if ($postdata["Date"] != "") {
  980.         // patch by Adriaan Tijsseling (http://kung-foo.tv) to properly sent back UTC
  981.             $post_date = mysql2date("Ymd\TH:i:s", $postdata['Date'], 1, 1);
  982.             $content  = "<title>".stripslashes($postdata["Title"])."</title>";
  983.             $content .= "<category>".$postdata["Category"]."</category>";
  984.             $content .= stripslashes($postdata["Content"]);
  985.  
  986.             $struct = new xmlrpcval(array("userid" => new xmlrpcval($postdata["Author_ID"]),
  987.                                           "dateCreated" => new xmlrpcval($post_date,"dateTime.iso8601"),
  988.                                           "content" => new xmlrpcval($content),
  989.                                           "postid" => new xmlrpcval($postdata["ID"])
  990.                                           ),"struct");
  991.  
  992.             $resp = $struct;
  993.             return new xmlrpcresp($resp);
  994.         } else {
  995.         return new xmlrpcresp(0, $xmlrpcerruser+3, // user error 4
  996.        "No such post #$post_ID");
  997.         }
  998.     } else {
  999.         return new xmlrpcresp(0, $xmlrpcerruser+3, // user error 3
  1000.        'Wrong username/password combination '.$username.' / '.starify($password));
  1001.     }
  1002. }
  1003.  
  1004.  
  1005.  
  1006. ### blogger.getRecentPosts ###
  1007.  
  1008. $bloggergetrecentposts_sig=array(array($xmlrpcArray, $xmlrpcString, $xmlrpcString, $xmlrpcString, $xmlrpcString, $xmlrpcInt));
  1009.  
  1010. $bloggergetrecentposts_doc='fetches X most recent posts, blogger-api like';
  1011.  
  1012. function bloggergetrecentposts($m) {
  1013.     global $wpdb;
  1014.     global $xmlrpcerruser,$tableposts;
  1015.  
  1016.     error_reporting(0); // there is a bug in phpxmlrpc that makes it say there are errors while the output is actually valid, so let's disable errors for that function
  1017.  
  1018.  
  1019.     $blogid = 1;    // we don't need that yet
  1020.  
  1021.     $numposts=$m->getParam(4);
  1022.     $numposts = $numposts->scalarval();
  1023.  
  1024.     if ($numposts > 0) {
  1025.         $limit = " LIMIT $numposts";
  1026.     } else {
  1027.         $limit = "";
  1028.     }
  1029.  
  1030.     $username=$m->getParam(2);
  1031.     $username = $username->scalarval();
  1032.  
  1033.     $password=$m->getParam(3);
  1034.     $password = $password->scalarval();
  1035.  
  1036.     if (user_pass_ok($username,$password)) {
  1037.  
  1038.         $sql = "SELECT * FROM $tableposts ORDER BY post_date DESC".$limit;
  1039.         $result = $wpdb->get_results($sql);
  1040.         if (!$result)
  1041.             return new xmlrpcresp(0, $xmlrpcerruser+2, // user error 2
  1042.        "For some strange yet very annoying reason, the entries couldn't be fetched.");
  1043.  
  1044.         $data = new xmlrpcval("","array");
  1045.  
  1046.         $i = 0;
  1047.         foreach ($result as $row) {
  1048.             $postdata = array(
  1049.                 "ID" => $row->ID,
  1050.                 "Author_ID" => $row->post_author,
  1051.                 "Date" => $row->post_date,
  1052.                 "Content" => $row->post_content,
  1053.                 "Title" => $row->post_title,
  1054.                 "Category" => $row->post_category
  1055.             );
  1056.  
  1057.         // patch by Adriaan Tijsseling (http://kung-foo.tv) to properly sent back UTC
  1058.             $post_date = mysql2date("Ymd\TH:i:s", $postdata['Date'], 1, 1);
  1059.             $content  = "<title>".stripslashes($postdata["Title"])."</title>";
  1060.             $content .= "<category>".get_cat_name($postdata["Category"])."</category>";
  1061.             $content .= stripslashes($postdata["Content"]);
  1062.  
  1063. //            $content = convert_chars($content,"html");
  1064. //            $content = $postdata["Title"];
  1065.  
  1066.             $category = new xmlrpcval($postdata['Category']);
  1067.  
  1068.             $authordata = get_userdata($postdata["Author_ID"]);
  1069.             switch($authordata["user_idmode"]) {
  1070.                 case "nickname":
  1071.                     $authorname = $authordata["user_nickname"];
  1072.  
  1073.             case "login":
  1074.                     $authorname = $authordata["user_login"];
  1075.                     break;
  1076.             case "firstname":
  1077.                     $authorname = $authordata["user_firstname"];
  1078.                     break;
  1079.             case "lastname":
  1080.                     $authorname = $authordata["user_lastname"];
  1081.                     break;
  1082.             case "namefl":
  1083.                     $authorname = $authordata["user_firstname"]." ".$authordata["user_lastname"];
  1084.                     break;
  1085.             case "namelf":
  1086.                     $authorname = $authordata["user_lastname"]." ".$authordata["user_firstname"];
  1087.                     break;
  1088.             default:
  1089.                     $authorname = $authordata["user_nickname"];
  1090.                     break;
  1091.             }
  1092.  
  1093.             $struct[$i] = new xmlrpcval(array("authorName" => new xmlrpcval($authorname),
  1094.                                         "userid" => new xmlrpcval($postdata["Author_ID"]),
  1095.                                         "dateCreated" => new xmlrpcval($post_date,"dateTime.iso8601"),
  1096.                                         "content" => new xmlrpcval($content),
  1097.                                         "postid" => new xmlrpcval($postdata["ID"]),
  1098.                                         'category' => $category
  1099.                                         ),"struct");
  1100.             $i = $i + 1;
  1101.         }
  1102.  
  1103.         $data = array($struct[0]);
  1104.         for ($j=1; $j<$i; $j++) {
  1105.             array_push($data, $struct[$j]);
  1106.         }
  1107.  
  1108.         $resp = new xmlrpcval($data, "array");
  1109.  
  1110.         return new xmlrpcresp($resp);
  1111.  
  1112.     } else {
  1113.         return new xmlrpcresp(0, $xmlrpcerruser+3, // user error 3
  1114.        'Wrong username/password combination '.$username.' / '.starify($password));
  1115.     }
  1116. }
  1117.  
  1118.  
  1119.  
  1120. ### blogger.getTemplate ###
  1121.  
  1122. # note: on b2, it fetches your $blogfilename, or b2.php if you didn't specify the variable
  1123.  
  1124. $bloggergettemplate_sig=array(array($xmlrpcString, $xmlrpcString, $xmlrpcString, $xmlrpcString, $xmlrpcString, $xmlrpcString));
  1125.  
  1126. $bloggergettemplate_doc='returns the default template file\'s code';
  1127.  
  1128. function bloggergettemplate($m) {
  1129.     global $xmlrpcerruser,$tableusers;
  1130.  
  1131.     error_reporting(0); // there is a bug in phpxmlrpc that makes it say there are errors while the output is actually valid, so let's disable errors for that function
  1132.  
  1133.  
  1134.     $blogid = 1;    // we do not need this yet
  1135.  
  1136.     $templateType=$m->getParam(4);
  1137.     $templateType = $templateType->scalarval();
  1138.  
  1139.     $username=$m->getParam(2);
  1140.     $username = $username->scalarval();
  1141.  
  1142.     $password=$m->getParam(3);
  1143.     $password = $password->scalarval();
  1144.  
  1145.     $userdata = get_userdatabylogin($username);
  1146.  
  1147.     if ($userdata->user_level < 3) {
  1148.         return new xmlrpcresp(0, $xmlrpcerruser+1, // user error 1
  1149.        "Sorry, users whose level is less than 3, can not edit the template.");
  1150.     }
  1151.  
  1152.     if (user_pass_ok($username,$password)) {
  1153.  
  1154.     if ($templateType == "main") {
  1155.         if (get_settings('blogfilename') != '') {
  1156.             $file = get_settings('blogfilename');
  1157.         } else {
  1158.             $file = "wp.php";
  1159.         }
  1160.     } elseif ($templateType == "archiveIndex") {
  1161.         $file = "wp.php";
  1162.     }
  1163.  
  1164.     $f = fopen($file,"r");
  1165.     $content = fread($f,filesize($file));
  1166.     fclose($file);
  1167.  
  1168.     $content = str_replace("\n","\r\n",$content);    // so it is actually editable with a windows/mac client, instead of being returned as a looooooooooong line of code
  1169.  
  1170.     return new xmlrpcresp(new xmlrpcval("$content"));
  1171.  
  1172.     } else {
  1173.         return new xmlrpcresp(0, $xmlrpcerruser+3, // user error 3
  1174.        'Wrong username/password combination '.$username.' / '.starify($password));
  1175.     }
  1176. }
  1177.  
  1178.  
  1179.  
  1180. ### blogger.setTemplate ###
  1181.  
  1182. # note: on b2, it saves that in your $blogfilename, or b2.php if you didn't specify the variable
  1183.  
  1184. $bloggersettemplate_sig=array(array($xmlrpcBoolean, $xmlrpcString, $xmlrpcString, $xmlrpcString, $xmlrpcString, $xmlrpcString, $xmlrpcString));
  1185.  
  1186. $bloggersettemplate_doc='saves the default template file\'s code';
  1187.  
  1188. function bloggersettemplate($m) {
  1189.     global $xmlrpcerruser, $tableusers;
  1190.  
  1191.     error_reporting(0); // there is a bug in phpxmlrpc that makes it say there are errors while the output is actually valid, so let's disable errors for that function
  1192.  
  1193.  
  1194.     $blogid = 1;    // we do not need this yet
  1195.  
  1196.     $template=$m->getParam(4);
  1197.     $template = $template->scalarval();
  1198.  
  1199.     $templateType=$m->getParam(5);
  1200.     $templateType = $templateType->scalarval();
  1201.  
  1202.     $username=$m->getParam(2);
  1203.     $username = $username->scalarval();
  1204.  
  1205.     $password=$m->getParam(3);
  1206.     $password = $password->scalarval();
  1207.  
  1208.     $userdata = get_userdatabylogin($username);
  1209.  
  1210.     if ($userdata->user_level < 3) {
  1211.         return new xmlrpcresp(0, $xmlrpcerruser+1, // user error 1
  1212.        "Sorry, users whose level is less than 3, can not edit the template.");
  1213.     }
  1214.  
  1215.     if (user_pass_ok($username,$password)) {
  1216.  
  1217.     if ($templateType == 'main') {
  1218.         if (get_settings('blogfilename') != '') {
  1219.             $file = get_settings('blogfilename');
  1220.         } else {
  1221.             $file = "wp.php";
  1222.         }
  1223.     } elseif ($templateType == "archiveIndex") {
  1224.         $file = "wp.php";
  1225.     }
  1226.  
  1227.     $f = fopen($file,"w+");
  1228.     fwrite($f, $template);
  1229.     fclose($file);
  1230.  
  1231.     return new xmlrpcresp(new xmlrpcval(true, "boolean"));
  1232.  
  1233.     } else {
  1234.         return new xmlrpcresp(0, $xmlrpcerruser+3, // user error 3
  1235.        'Wrong username/password combination '.$username.' / '.starify($password));
  1236.     }
  1237. }
  1238.  
  1239. /**** /Blogger API ****/
  1240.  
  1241.  
  1242.  
  1243. /**** metaWeblog API ****/
  1244.  
  1245. /**********************
  1246.  *
  1247.  * metaWeblog API extensions
  1248.  * added by 
  1249.  *  Dougal Campbell <dougal@gunters.org> 
  1250.  *  http://dougal.gunters.org/
  1251.  *
  1252.  **********************/
  1253.  
  1254. $mwnewpost_sig =  array(array($xmlrpcString,$xmlrpcString,$xmlrpcString,$xmlrpcString,$xmlrpcStruct,$xmlrpcBoolean));
  1255. $mwnewpost_doc = 'Add a post, MetaWeblog API-style';
  1256.  
  1257. function mwnewpost($params) {
  1258.     global $xmlrpcerruser;
  1259.     global $blog_ID, $cache_userdata,$tableposts;
  1260.     global $use_rss, $post_default_title;
  1261.     global $post_default_category,$cafelogID,$sleep_after_edit;
  1262.  
  1263.     $xblogid = $params->getParam(0);
  1264.     $xuser = $params->getParam(1);
  1265.     $xpass = $params->getParam(2);
  1266.     $xcontent = $params->getParam(3);
  1267.     $xpublish = $params->getParam(4);
  1268.     
  1269.     $blogid = $xblogid->scalarval();
  1270.     $username = $xuser->scalarval();
  1271.     $password = $xpass->scalarval();
  1272.     $contentstruct = phpxmlrpc_decode($xcontent);
  1273.     $post_status = $xpublish->scalarval()?'publish':'draft';
  1274.  
  1275.     // Check login
  1276.     if (user_pass_ok($username,$password)) {
  1277.         $userdata = get_userdatabylogin($username);
  1278.         $post_author = $userdata->ID;
  1279.         $user_level = $userdata->user_level;
  1280.         if ($user_level < 1) {
  1281.             return new xmlrpcresp(0, $xmlrpcerruser+1,
  1282.               "Sorry, level 0 users cannot post");
  1283.         }
  1284.  
  1285.  
  1286.         $post_title = $contentstruct['title'];
  1287.         $post_content = format_to_post($contentstruct['description']);
  1288.  
  1289.         $post_excerpt = $contentstruct['mt_excerpt'];
  1290.         $post_more = $contentstruct['mt_text_more'];
  1291.  
  1292.         $comment_status = $contentstruct['mt_allow_comments']?'open':'closed';
  1293.         $ping_status = $contentstruct['mt_allow_pings']?'open':'closed';
  1294.  
  1295.         if ($post_more) {
  1296.             $post_content = $post_content . "\n<!--more-->\n" . $post_more;
  1297.         }
  1298.         
  1299.         // Do some timestamp voodoo
  1300.     // Patched by Adriaan Tijsseling (http://kung-foo.tv) to properly deal with UTC date strings -->
  1301.         $dateCreated = $contentstruct['dateCreated'];
  1302.         $utc = $dateCreated[strlen($dateCreated)-1] == 'Z';
  1303.         $dateCreated = $dateCreated ? iso8601_decode($dateCreated,$utc) : current_time('timestamp',1);
  1304.         $post_date = gmdate('Y-m-d H:i:s', $dateCreated + get_settings('gmt_offset') * 3600);
  1305.         $post_date_gmt = get_gmt_from_date(date('Y-m-d H:i:s', $dateCreated));
  1306.     // <-- end patch
  1307.         
  1308.         $catnames = $contentstruct['categories'];
  1309. logio("O","Post cats: " . print_r($catnames));
  1310.         $post_category = array();
  1311.         if ($catnames) {
  1312.             foreach ($catnames as $cat) {
  1313.                 $post_category[] = get_cat_ID($cat);
  1314.             }
  1315.         } else {
  1316.             $post_category = 0;
  1317.         }
  1318.         
  1319.         // We've got all the data -- post it:
  1320.         $postarr = compact('post_author','post_date','post_date_gmt','post_content','post_title','post_category','post_status','post_excerpt','comment_status','ping_status');
  1321.  
  1322.         $post_ID = wp_insert_post($postarr);
  1323.         
  1324.         if (!$post_ID) {
  1325.             return new xmlrpcresp(0, $xmlrpcerruser+2, "For some strange yet very annoying reason, your entry could not be posted.");
  1326.         }
  1327.  
  1328.         if (!isset($blog_ID)) { $blog_ID = 1; }
  1329.  
  1330.         if (isset($sleep_after_edit) && $sleep_after_edit > 0) {
  1331.             sleep($sleep_after_edit);
  1332.         }
  1333.  
  1334.         pingback($content, $post_ID);
  1335.         trackback_url_list($content_struct['mt_tb_ping_urls'],$post_ID);
  1336.  
  1337.         logIO("O","(MW) Posted ! ID: $post_ID");
  1338.         $myResp = new xmlrpcval($post_ID,"string");
  1339.  
  1340.         return new xmlrpcresp($myResp);
  1341.  
  1342.     } else {
  1343.         logIO("O","(MW) Wrong username/password combination <b>$username / $password</b>");
  1344.         return new xmlrpcresp(0, $xmlrpcerruser+3, // user error 3
  1345.        'Wrong username/password combination '.$username.' / '.starify($password));
  1346.     }
  1347. }
  1348.  
  1349. $mweditpost_sig =  array(array($xmlrpcBoolean,$xmlrpcString,$xmlrpcString,$xmlrpcString,$xmlrpcStruct,$xmlrpcBoolean));
  1350. $mweditpost_doc = 'Edit a post, MetaWeblog API-style';
  1351.  
  1352. function mweditpost ($params) {    // ($postid, $user, $pass, $content, $publish) 
  1353.     global $xmlrpcerruser;
  1354.  
  1355.     $xpostid = $params->getParam(0);
  1356.     $xuser = $params->getParam(1);
  1357.     $xpass = $params->getParam(2);
  1358.     $xcontent = $params->getParam(3);
  1359.     $xpublish = $params->getParam(4);
  1360.     
  1361.     $ID = $xpostid->scalarval();
  1362.     $username = $xuser->scalarval();
  1363.     $password = $xpass->scalarval();
  1364.     $contentstruct = phpxmlrpc_decode($xcontent);
  1365.     $postdata = wp_get_single_post($ID,ARRAY_A);
  1366.  
  1367.     if (!$postdata)
  1368.         return new xmlrpcresp(0, $xmlrpcerruser+2, // user error 2
  1369.             "No such post $ID.");
  1370.             
  1371.     $userdata = get_userdatabylogin($username);
  1372.     $user_ID = $userdata->ID;
  1373.     $user_level = $userdata->user_level;
  1374.     $time_difference = get_settings('gmt_offset');
  1375.     
  1376.     $post_author_ID = $postdata['post_author'];
  1377.     $post_authordata = get_userdata($post_author_ID);
  1378.  
  1379.     if (($user_ID != $post_author_ID) && ($user_level <= $post_authordata->user_level)) {
  1380.         return new xmlrpcresp(0, $xmlrpcerruser+1, // user error 1
  1381.             "Sorry, you do not have the right to edit this post.");
  1382.     }
  1383.         
  1384.     // Check login
  1385.     if (user_pass_ok($username,$password)) {
  1386.         if ($user_level < 1) {
  1387.             return new xmlrpcresp(0, $xmlrpcerruser+1,
  1388.  
  1389.               "Sorry, level 0 users cannot edit posts");
  1390.         }
  1391.  
  1392.         extract($postdata);
  1393.  
  1394.         $post_title = $contentstruct['title'];
  1395.         $post_content = format_to_post($contentstruct['description']);
  1396.         $catnames = $contentstruct['categories'];
  1397.         
  1398.         if ($catnames) {
  1399.             foreach ($catnames as $cat) {
  1400.                 $post_category[] = get_cat_ID($cat);
  1401.             }
  1402.         }
  1403.  
  1404.         $post_excerpt = $contentstruct['mt_excerpt'];
  1405.         $post_more = $contentstruct['mt_text_more'];
  1406.         $post_status = $xpublish->scalarval()?'publish':'draft';
  1407.         if ($post_more) {
  1408.             $post_content = $post_content . "\n<!--more-->\n" . $post_more;
  1409.         }
  1410.         $comment_status = (1 == $contentstruct['mt_allow_comments'])?'open':'closed';
  1411.         $ping_status = $contentstruct['mt_allow_pings']?'open':'closed';
  1412.  
  1413.         // Do some timestamp voodoo
  1414.     // Patched by Adriaan Tijsseling (http://kung-foo.tv) to properly deal with UTC date strings -->
  1415.         $dateCreated = $contentstruct['dateCreated'];
  1416.         $utc = $dateCreated[strlen($dateCreated)-1] == 'Z';
  1417.         $dateCreated = $dateCreated ? iso8601_decode($dateCreated,$utc) : current_time('timestamp',1);
  1418.         $post_date = gmdate('Y-m-d H:i:s', $dateCreated + get_settings('gmt_offset') * 3600);
  1419.         $post_date_gmt = get_gmt_from_date(date('Y-m-d H:i:s', $dateCreated));
  1420.     // <-- end patch
  1421.  
  1422.         // We've got all the data -- post it:
  1423.         $newpost = compact('ID','post_content','post_title','post_category','post_status','post_excerpt','comment_status','ping_status','post_date','post_date_gmt');
  1424.  
  1425.         $newpost_ID = wp_update_post($newpost);
  1426.         
  1427.         if (!$newpost_ID) {
  1428.             return new xmlrpcresp(0, $xmlrpcerruser+2, "For some strange yet very annoying reason, your entry could not be posted.");
  1429.         }
  1430.  
  1431.         if (!isset($blog_ID)) { $blog_ID = 1; }
  1432.  
  1433.         if (isset($sleep_after_edit) && $sleep_after_edit > 0) {
  1434.             sleep($sleep_after_edit);
  1435.         }
  1436.  
  1437.         pingback($content, $ID);
  1438.         trackback_url_list(implode(",", $contentstruct['mt_tb_ping_urls']),$ID);
  1439.  
  1440.         logIO("O","(MW) Edited ! ID: $ID");
  1441.         $myResp = new xmlrpcval(true,"boolean");
  1442.  
  1443.         return new xmlrpcresp($myResp);
  1444.  
  1445.     } else {
  1446.         logIO("O","(MW) Wrong username/password combination <b>$username / $password</b>");
  1447.         return new xmlrpcresp(0, $xmlrpcerruser+3, // user error 3
  1448.        'Wrong username/password combination '.$username.' / '.starify($password));
  1449.     }
  1450. }
  1451.  
  1452. $mwgetpost_sig =  array(array($xmlrpcStruct,$xmlrpcString,$xmlrpcString,$xmlrpcString));
  1453. $mwegetpost_doc = 'Get a post, MetaWeblog API-style';
  1454.  
  1455. function mwgetpost ($params) {    // ($postid, $user, $pass) 
  1456.     global $xmlrpcerruser;
  1457.     
  1458.     $xpostid = $params->getParam(0);
  1459.     $xuser = $params->getParam(1);
  1460.     $xpass = $params->getParam(2);
  1461.     
  1462.     $post_ID = $xpostid->scalarval();
  1463.     $username = $xuser->scalarval();
  1464.     $password = $xpass->scalarval();
  1465.  
  1466.     // Check login
  1467.     if (user_pass_ok($username,$password)) {
  1468.         $postdata = get_postdata($post_ID);
  1469.  
  1470.         if ($postdata["Date"] != "") {
  1471.  
  1472.         // patch by Adriaan Tijsseling (http://kung-foo.tv) to properly sent back UTC
  1473.             $post_date = mysql2date('Ymd\TH:i:s', $postdata['Date'], 1, 1);
  1474.             $catids = wp_get_post_cats($post_ID);
  1475.             foreach($catids as $catid) {
  1476.                 $catname = get_cat_name($catid);
  1477.                 $catnameenc = new xmlrpcval($catname);
  1478.                 $catlist[] = $catnameenc;
  1479.             }            
  1480.             $post = get_extended($postdata['Content']);
  1481.             $allow_comments = ('open' == $postdata['comment_status'])?1:0;
  1482.             $allow_pings = ('open' == $postdata['ping_status'])?1:0;
  1483.  
  1484.             // Retrun if Markdown is active or not. Useful for ecto.
  1485.             // without this, ecto could apply "Convert linebreaks" sometimes.
  1486.             $current_plugins = explode("\n", (get_settings('active_plugins')));
  1487.             if (!empty($current_plugins) && in_array( "markdown.php", $current_plugins)) {
  1488.                 $mt_convert_breaks = 'markdown';
  1489.             } else {
  1490.                 $mt_convert_breaks = '__default__';
  1491.             }
  1492.  
  1493.             $resp = array(
  1494.                 'link' => new xmlrpcval(get_permalink($post_ID)),
  1495.                 'title' => new xmlrpcval($postdata["Title"]),
  1496.                 'description' => new xmlrpcval($post['main']),
  1497.                 'dateCreated' => new xmlrpcval($post_date,'dateTime.iso8601'),
  1498.                 'userid' => new xmlrpcval($postdata["Author_ID"]),
  1499.                 'postid' => new xmlrpcval($postdata["ID"]),
  1500.                 'content' => new xmlrpcval($postdata["Content"]),
  1501.                 'permaLink' => new xmlrpcval(get_permalink($post_ID)),
  1502.                 // Disable this field. use 'mt.getPostCategories instead
  1503.                 //'categories' => new xmlrpcval($catlist,'array'), 
  1504.                 'mt_excerpt' => new xmlrpcval($postdata['Excerpt']),
  1505.                 'mt_allow_comments' => new xmlrpcval($allow_comments,'int'),
  1506.                 'mt_allow_pings' => new xmlrpcval($allow_pings,'int'),
  1507.                 'mt_text_more' => new xmlrpcval($post['extended']),
  1508.                 'mt_convert_breaks' => new xmlrpcval($mt_convert_breaks)
  1509.             );
  1510.             
  1511.             $resp = new xmlrpcval($resp,'struct');
  1512.             
  1513.             return new xmlrpcresp($resp);
  1514.         } else {
  1515.         return new xmlrpcresp(0, $xmlrpcerruser+3, // user error 4
  1516.             "No such post #$post_ID");
  1517.         }
  1518.     } else {
  1519.         return new xmlrpcresp(0, $xmlrpcerruser+3, // user error 3
  1520.        'Wrong username/password combination '.$username.' / '.starify($password));
  1521.     }
  1522.  
  1523. }
  1524.  
  1525. $mwrecentposts_sig =  array(array($xmlrpcArray,$xmlrpcString,$xmlrpcString,$xmlrpcString,$xmlrpcInt));
  1526. $mwerecentposts_doc = 'Get recent posts, MetaWeblog API-style';
  1527.  
  1528. function mwrecentposts ($params) {    // ($blogid, $user, $pass, $num) 
  1529.     global $xmlrpcerruser;
  1530.  
  1531.     $xblogid = $params->getParam(0);
  1532.     $xuser = $params->getParam(1);
  1533.     $xpass = $params->getParam(2);
  1534.     $xnum = $params->getParam(3);
  1535.     
  1536.     $blogid = $xblogid->scalarval();
  1537.     $username = $xuser->scalarval();
  1538.     $password = $xpass->scalarval();
  1539.     $num = $xnum->scalarval();
  1540.  
  1541.     // Check login
  1542.     if (user_pass_ok($username,$password)) {
  1543.  
  1544.         $postlist = wp_get_recent_posts($num);
  1545.         
  1546.         // Build response packet. We can't just use xmlrpc_encode,
  1547.         // because of the dateCreated field, which must be a date type.
  1548.         
  1549.         // Encode each entry of the array.
  1550.         foreach($postlist as $entry) {
  1551.  
  1552.         // patch by Adriaan Tijsseling (http://kung-foo.tv) to properly sent back UTC
  1553.             $isoString = mysql2date('Ymd\TH:i:s', $entry['post_date'], 1, 1 );
  1554.             $date = new xmlrpcval($isoString,"dateTime.iso8601");
  1555.             $userid = new xmlrpcval($entry['post_author']);
  1556.             $content = new xmlrpcval($entry['post_content']);
  1557.             $excerpt = new xmlrpcval($entry['post_excerpt']);
  1558.             
  1559.             // $pcat = stripslashes(get_cat_name($entry['post_category']));
  1560.             
  1561.             // For multiple cats, we might do something like
  1562.             // this in the future:
  1563.             //$catstruct['description'] = $pcat;
  1564.             //$catstruct['categoryId'] = $entry['post_category'];
  1565.             //$catstruct['categoryName'] = $pcat;
  1566.             //$catstruct['isPrimary'] = TRUE;
  1567.             
  1568.             //$catstruct2 = phpxmlrpc_encode($catstruct);
  1569.  
  1570.             $catids = wp_get_post_cats('1', $entry['ID']);
  1571.         
  1572.             // This should return multiple categories correctly
  1573.             foreach($catids as $catid) {    
  1574.                 $catarray[] = new xmlrpcval(get_cat_name($catid),'string');
  1575.             }
  1576.             
  1577.             $categories = new xmlrpcval($catarray,'array');
  1578.  
  1579.             $post = get_extended($entry['post_content']);
  1580.  
  1581.             $postid = new xmlrpcval($entry['ID']);
  1582.             $title = new xmlrpcval(stripslashes($entry['post_title']));
  1583.             $description = new xmlrpcval(stripslashes($post['main']));
  1584.             $link = new xmlrpcval(get_permalink($entry['ID']));
  1585.             $permalink = $link;
  1586.  
  1587.             $extended = new xmlrpcval(stripslashes($post['extended']));
  1588.  
  1589.             $allow_comments = new xmlrpcval((('open' == $entry['comment_status'])?1:0),'int');
  1590.             $allow_pings = new xmlrpcval((('open' == $entry['ping_status'])?1:0),'int');
  1591.  
  1592.             $encode_arr = array(
  1593.                 'dateCreated' => $date,
  1594.                 'userid' => $userid,
  1595.                 'postid' => $postid,
  1596.                 'categories' => $categories,
  1597.                 'title' => $title,
  1598.                 'description' => $description,
  1599.                 'link' => $link,
  1600.                 'permaLink' => $permalink,
  1601.                 'mt_excerpt' => $excerpt,
  1602.                 'mt_allow_comments' => $allow_comments,
  1603.                 'mt_allow_pings' => $allow_pings,
  1604.                 'mt_text_more' => $extended
  1605.             );
  1606.             
  1607.             $xmlrpcpostarr[] = new xmlrpcval($encode_arr,"struct");
  1608.         }    
  1609.  
  1610.         // Now convert that to an xmlrpc array type
  1611.         $myResp = new xmlrpcval($xmlrpcpostarr,"array");
  1612.  
  1613.         return new xmlrpcresp($myResp);
  1614.     } else {
  1615.         return new xmlrpcresp(0, $xmlrpcerruser+3, // user error 3
  1616.        'Wrong username/password combination '.$username.' / '.starify($password));
  1617.     }
  1618. }
  1619.  
  1620.  
  1621. $mwgetcats_sig =  array(array($xmlrpcArray,$xmlrpcString,$xmlrpcString,$xmlrpcString));
  1622. $mwgetcats_doc = 'Get a post, MetaWeblog API-style';
  1623.  
  1624. function mwgetcats ($params) {    // ($blogid, $user, $pass) 
  1625.     global $xmlrpcerruser,$wpdb,$tablecategories;
  1626.     global $querystring_start, $querystring_equal, $querystring_separator;
  1627.     
  1628.     $blog_URL = get_settings('home') . '/' . get_settings('blogfilename');
  1629.     
  1630.     $arr = array();
  1631.  
  1632.     if ($cats = $wpdb->get_results("SELECT cat_ID,cat_name FROM $tablecategories",ARRAY_A)) {
  1633.         foreach ($cats as $cat) {
  1634.             $struct['categoryId'] = $cat['cat_ID'];
  1635.             $struct['description'] = $cat['cat_name'];
  1636.             $struct['categoryName'] = $cat['cat_name'];
  1637.             $struct['htmlUrl'] = htmlspecialchars($blog_URL . $querystring_start . 'cat' . $querystring_equal . $cat['cat_ID']);
  1638.             $struct['rssUrl'] = ''; // will probably hack alexking's stuff in here
  1639.             
  1640.             $arr[] = phpxmlrpc_encode($struct);
  1641.         }
  1642.     }
  1643.     
  1644.     $resp = new xmlrpcval($arr,'array');
  1645.  
  1646.     return new xmlrpcresp($resp);
  1647. }
  1648.  
  1649.  
  1650. $mwnewmedia_sig =  array(array($xmlrpcStruct,$xmlrpcString,$xmlrpcString,$xmlrpcString,$xmlrpcStruct));
  1651. $mwnewmedia_doc = 'Upload image or other binary data, MetaWeblog API-style';
  1652.  
  1653. /*  File Upload in WordPress XML-RPC 
  1654.  
  1655.  
  1656.  metaWeblog.newMediaObject (blogid, username, password, struct)
  1657.  
  1658.  The blogid, username and password params are as in the Blogger API. 
  1659.  
  1660.  The struct must contain at least three elements, name, type and bits.
  1661.  
  1662.  name is a string, it may be used to determine the name of the file 
  1663.  that stores the object, or to display it in a list of objects. 
  1664.  It determines how the weblog refers to the object. If the name is 
  1665.  the same as an existing object stored in the weblog, it may replace 
  1666.  the existing object.
  1667.  
  1668.  type is a string, it indicates the type of the object, it's a standard 
  1669.  MIME type, like audio/mpeg or image/jpeg or video/quicktime. 
  1670.  
  1671.  bits is a base64-encoded binary value containing the content of the object.
  1672.  
  1673.  The struct may contain other elements, which may or may not be stored by 
  1674.  the content management system.
  1675.  
  1676.  If newMediaObject fails, it throws an error. If it succeeds, it returns 
  1677.  a struct, which must contain at least one element, url, which is the url 
  1678.  through which the object can be accessed. It must be either an FTP or HTTP url.
  1679.  
  1680. */
  1681.  
  1682. function mwnewmedia($params) {    // ($blogid, $user, $pass, $struct) 
  1683.     global $xmlrpcerruser;
  1684.  
  1685.     $xblogid = $params->getParam(0);
  1686.     $xuser = $params->getParam(1);
  1687.     $xpass = $params->getParam(2);
  1688.     $xdata = $params->getParam(3);
  1689.     
  1690.     $blogid = $xblogid->scalarval();
  1691.     $username = $xuser->scalarval();
  1692.     $password = $xpass->scalarval();
  1693.     $datastruct = phpxmlrpc_decode($xdata);
  1694.  
  1695.     $name = $datastruct['name'];
  1696.     $type = $datastruct['type'];
  1697.     $bits = $datastruct['bits'];
  1698.     
  1699.     $file_realpath = get_settings('fileupload_realpath'); 
  1700.     $file_url = get_settings('fileupload_url');
  1701.  
  1702.     $userdata = get_userdatabylogin($username);
  1703.     $userlevel = $userdata->user_level;
  1704.  
  1705.     if (user_pass_ok($username,$password)) {
  1706.         if( !get_settings('use_fileupload')) {
  1707.             // Uploads not allowed
  1708.             logIO("O","(MW) Uploads not allowed");
  1709.             return new xmlrpcresp(0, $xmlrpcerruser+3, // user error 3
  1710.                        'No uploads allowed for this site');
  1711.         } 
  1712.         
  1713.         if( get_settings('fileupload_minlevel') > $userlevel) {
  1714.             // User has not enough privileges
  1715.             logIO("O","(MW) Not enough privilege");
  1716.             return new xmlrpcresp(0, $xmlrpcerruser+3, // user error 3
  1717.                        $username.' is not allowed to upload files to this site');
  1718.         }
  1719.  
  1720.         if( $file_realpath == "" || $file_url == "" ) {
  1721.             // WordPress is not correctly configured
  1722.             logIO("O","(MW) Bad configuration. Real/URL path not defined");
  1723.             return new xmlrpcresp(0, $xmlrpcerruser+3, // user error 3
  1724.                        'Please configure WordPress with valid paths for file upload');
  1725.         }
  1726.         
  1727.         $prefix = "/";
  1728.         
  1729.         if( !empty($name)) {
  1730.             // Create the path
  1731.             $localpath = $file_realpath.$prefix.$name;
  1732.             $url = $file_url.$prefix.$name;
  1733.  
  1734.             /* encode & write data (binary) */
  1735.             $ifp = fopen( $localpath, "wb" );
  1736.             $success = fwrite( $ifp, $bits );
  1737.             fclose( $ifp );
  1738.             chmod( $localpath, 0666 );
  1739.  
  1740.             if( $success ) {
  1741.                 $resp = array(
  1742.                             'url' => new xmlrpcval( $url ),
  1743.                         );
  1744.                 
  1745.                 $resp = new xmlrpcval($resp,'struct');
  1746.                 return new xmlrpcresp($resp);
  1747.             } else {
  1748.                 return new xmlrpcresp(0, $xmlrpcerruser+3, 
  1749.                                   'Could not write file '.$name.' to '.$localpath );
  1750.             }
  1751.         }
  1752.     
  1753.     } else {
  1754.         logIO("O","(MW) Wrong username/password combination <b>$username / $password</b>");
  1755.         return new xmlrpcresp(0, $xmlrpcerruser+3, // user error 3
  1756.        'Wrong username/password combination '.$username.' / '.starify($password));
  1757.     }
  1758.  
  1759.     /*    
  1760.     return new xmlrpcresp(0, $xmlrpcerruser+10, // user error 10
  1761.       'metaWeblog.newMediaObject not implemented (yet)');
  1762.     */
  1763. }
  1764.  
  1765.  
  1766. /**** /MetaWeblog API ****/
  1767.  
  1768.  
  1769. /**** MovableType API ****/
  1770.  
  1771. /**********************
  1772.  *
  1773.  * MovableType API extensions
  1774.  * added by 
  1775.  *  Dougal Campbell <dougal@gunters.org> 
  1776.  *  http://dougal.gunters.org/
  1777.  *
  1778.  * DONE:
  1779.  *  mt.getCategoryList
  1780.  *  mt.setPostCategories
  1781.  *  mt.supportedMethods
  1782.  *  mt.getPostCategories
  1783.  *  mt.publishPost
  1784.  *  mt.getRecentPostTitles
  1785.  *  extend metaWeblog.newPost
  1786.  *  extend metaWeblog.editPost
  1787.  *  extend metaWeblog.getPost
  1788.  *  extend metaWeblog.getRecentPosts
  1789.  *
  1790.  * PARTIALLY DONE:
  1791.  *  mt.supportedTextFilters        // empty stub, because WP doesn't support per-post text filters at this time
  1792.  *  mt.getTrackbackPings        // another stub.
  1793.  *  metaWeblog.newMediaObject    // ditto. For now.
  1794.  *
  1795.  **********************/
  1796.  
  1797. $mt_supportedMethods_sig = array(array($xmlrpcArray));
  1798. $mt_supportedMethods_doc = 'Retrieve information about the XML-RPC methods supported by the server.';
  1799.  
  1800. // ripped out of system.listMethods
  1801. function mt_supportedMethods($params) {
  1802.     global $dispatch_map, $xmlrpcerr, $xmlrpcstr, $_xmlrpcs_dmap;
  1803.     $v=new xmlrpcval();
  1804.     $dmap=$dispatch_map;
  1805.     $outAr=array();
  1806.     for(reset($dmap); list($key, $val)=each($dmap); ) {
  1807.     $outAr[]=new xmlrpcval($key, "string");
  1808.     }
  1809.     $dmap=$_xmlrpcs_dmap;
  1810.     for(reset($dmap); list($key, $val)=each($dmap); ) {
  1811.     $outAr[]=new xmlrpcval($key, "string");
  1812.     }
  1813.     $v->addArray($outAr);
  1814.     return new xmlrpcresp($v);
  1815.  
  1816. }
  1817.  
  1818. $mt_getPostCategories_sig = array(array($xmlrpcArray, $xmlrpcString, $xmlrpcString, $xmlrpcString));
  1819. $mt_getPostCategories_doc = "Returns a list of all categories to which the post is assigned.";
  1820.  
  1821. function mt_getPostCategories($params) {
  1822.     global $xmlrpcusererr;
  1823.  
  1824.     $xpostid = $params->getParam(0);
  1825.     $xuser = $params->getParam(1);
  1826.     $xpass = $params->getParam(2);
  1827.     
  1828.     $post_ID = $xpostid->scalarval();
  1829.     $username = $xuser->scalarval();
  1830.     $password = $xpass->scalarval();
  1831.  
  1832.     if (user_pass_ok($username,$password)) {
  1833.         $catids = wp_get_post_cats('1', $post_ID);
  1834.  
  1835.         // The first category listed will be set as primary
  1836.         $struct['isPrimary'] = true;
  1837.         foreach($catids as $catid) {    
  1838.             $struct['categoryId'] = $catid;
  1839.             $struct['categoryName'] = get_cat_name($catid);
  1840.  
  1841.             $resp_struct[] = phpxmlrpc_encode($struct);
  1842.             $struct['isPrimary'] = false;
  1843.         }
  1844.         
  1845.         // Return an array of structs    
  1846.         $resp_array = new xmlrpcval($resp_struct,'array');
  1847.         
  1848.         return new xmlrpcresp($resp_array);
  1849.  
  1850.     } else {
  1851.         return new xmlrpcresp(0, $xmlrpcerruser+3, // user error 3
  1852.        'Wrong username/password combination '.$username.' / '.starify($password));
  1853.     }
  1854. }
  1855.  
  1856. $mt_setPostCategories_sig = array(array($xmlrpcBoolean, $xmlrpcString, $xmlrpcString, $xmlrpcString, $xmlrpcArray));
  1857. $mt_setPostCategories_doc = "Sets the categories for a post";
  1858.  
  1859. function mt_setPostCategories($params) {
  1860.     global $xmlrpcusererr;
  1861.     
  1862.     $xpostid = $params->getParam(0);
  1863.     $xuser = $params->getParam(1);
  1864.     $xpass = $params->getParam(2);
  1865.     $xcats = $params->getParam(3);
  1866.     
  1867.     $post_ID = $xpostid->scalarval();
  1868.     $username = $xuser->scalarval();
  1869.     $password = $xpass->scalarval();
  1870.     $cats = phpxmlrpc_decode($xcats);
  1871.     
  1872.     foreach($cats as $cat) {
  1873.         $catids[] = $cat['categoryId'];
  1874.     }
  1875.     
  1876.     if (user_pass_ok($username,$password)) {
  1877.         wp_set_post_cats('', $post_ID, $catids);
  1878.         
  1879.         return new xmlrpcresp(new xmlrpcval(true,'boolean'));
  1880.     } else {
  1881.         return new xmlrpcresp(0, $xmlrpcerruser+3, // user error 3
  1882.        'Wrong username/password combination '.$username.' / '.starify($password));
  1883.     }
  1884. }
  1885.  
  1886. $mt_publishPost_sig = array(array($xmlrpcBoolean, $xmlrpcString, $xmlrpcString, $xmlrpcString));
  1887. $mt_publishPost_doc = "Publish (rebuild) all of the static files related to an entry. Equivalent to saving an entry in the system (but without the ping).";
  1888.  
  1889. function mt_publishPost($params) {
  1890.     global $xmlrpcusererr;
  1891.     
  1892.     $xpostid = $params->getParam(0);
  1893.     $xuser = $params->getParam(1);
  1894.     $xpass = $params->getParam(2);
  1895.     
  1896.     $post_ID = $xpostid->scalarval();
  1897.     $username = $xuser->scalarval();
  1898.     $password = $xpass->scalarval();
  1899.  
  1900.     if (user_pass_ok($username,$password)) {
  1901.         $postdata = wp_get_single_post($post_ID,ARRAY_A);
  1902.         
  1903.         $postdata['post_status'] = 'publish';
  1904.         
  1905.         // retain old cats
  1906.         $cats = wp_get_post_cats('',$post_ID);
  1907.         $postdata['post_category'] = $cats;
  1908.     
  1909.         $result = wp_update_post($postdata);
  1910.  
  1911.         return new xmlrpcresp(new xmlrpcval($result,'boolean'));
  1912.     } else {
  1913.         return new xmlrpcresp(0, $xmlrpcerruser+3, // user error 3
  1914.        'Wrong username/password combination '.$username.' / '.starify($password));
  1915.     }
  1916. }
  1917.  
  1918. $mt_getRecentPostTitles_sig = array(array($xmlrpcArray,$xmlrpcString,$xmlrpcString,$xmlrpcString,$xmlrpcInt));
  1919. $mt_getRecentPostTitles_doc = "Returns a bandwidth-friendly list of the most recent posts in the system.";
  1920.  
  1921. function mt_getRecentPostTitles($params) {
  1922.     global $xmlrpcusererr, $wpdb, $tableposts;
  1923.  
  1924.     $xblogid = $params->getParam(0);
  1925.     $xuser = $params->getParam(1);
  1926.     $xpass = $params->getParam(2);
  1927.     $xnumposts = $params->getParam(3);
  1928.  
  1929.     $blogid = $xblogid->scalarval();
  1930.     $username = $xuser->scalarval();
  1931.     $password = $xpass->scalarval();
  1932.     $numposts = intval($xnumposts->scalarval());
  1933.  
  1934.     if (user_pass_ok($username,$password)) {
  1935.         $sql = "SELECT post_date, post_author, ID, post_title FROM $tableposts ORDER BY post_date DESC LIMIT $numposts";
  1936.         $posts = $wpdb->get_results($sql,ARRAY_A);
  1937.         
  1938.         foreach($posts as $post) {
  1939.  
  1940.         // patch by Adriaan Tijsseling (http://kung-foo.tv) to properly sent back UTC
  1941.             $post_date = mysql2date('Ymd\TH:i:s', $post['post_date'], 1, 1);
  1942.             $struct['dateCreated'] = new xmlrpcval($post_date, 'dateTime.iso8601');
  1943.             $struct['userid'] = new xmlrpcval($post['post_author'], 'string');
  1944.             $struct['postid'] = new xmlrpcval($post['ID'], 'string');
  1945.             $struct['title'] = new xmlrpcval($post['post_title'], 'string');
  1946.             
  1947.             $result[] = new xmlrpcval($struct,'struct');
  1948.         }
  1949.         
  1950.         return new xmlrpcresp(new xmlrpcval($result,'array'));
  1951.  
  1952.     } else {
  1953.         return new xmlrpcresp(0, $xmlrpcerruser+3, // user error 3
  1954.        'Wrong username/password combination '.$username.' / '.starify($password));
  1955.     }
  1956. }
  1957.  
  1958.  
  1959. $mt_supportedTextFilters_sig = array(array($xmlrpcArray));
  1960. $mt_supportedTextFilters_doc = "Retrieve information about the text formatting plugins supported by the server. (not implemented)";
  1961.  
  1962. function mt_supportedTextFilters($params) {
  1963.     // This should probably check the status of the 'use_bbcode' 
  1964.     // and 'use_gmcode' config options.
  1965.     
  1966.     // Archaic Markdown check
  1967.     $current_plugins = explode("\n", (get_settings('active_plugins')));
  1968.     if (!empty($current_plugins) && in_array( "markdown.php", $current_plugins)) {
  1969.         $struct['label'] = 'Markdown';
  1970.         $struct['key'] = 'markdown';
  1971.     }
  1972.     
  1973.     $xmlstruct = phpxmlrpc_encode($struct);
  1974.     return new xmlrpcresp(new xmlrpcval(array($xmlstruct),'array'));
  1975. }
  1976.  
  1977.  
  1978.  
  1979. $mt_getTrackbackPings_sig = array(array($xmlrpcArray,$xmlrpcString));
  1980. $mt_getTrackbackPings_doc = "Retrieve the list of Trackback pings posted to a particular entry. (not implemented)";
  1981.  
  1982. function mt_getTrackbackPings($params) {
  1983.     $struct['pingTitle'] = '';
  1984.     $struct['pingURL'] = '';
  1985.     $struct['pingIP'] = '';
  1986.     
  1987.     $xmlstruct = phpxmlrpc_encode($struct);
  1988.     
  1989.     return new xmlrpcresp(new xmlrpcval(array($xmlstruct),'array'));
  1990. }
  1991.  
  1992.  
  1993.  
  1994. /**** /MovableType API ****/
  1995.  
  1996.  
  1997. /**** PingBack functions ****/
  1998.  
  1999. $pingback_ping_sig = array(array($xmlrpcString, $xmlrpcString, $xmlrpcString));
  2000.  
  2001. $pingback_ping_doc = 'Gets a pingback and registers it as a comment prefixed by <pingback />';
  2002.  
  2003. function pingback_ping($m) { // original code by Mort
  2004.     // (http://mort.mine.nu:8080)
  2005.     global $tableposts, $tablecomments, $wpdb; 
  2006.     global $wp_version; 
  2007.     global $wpdb;
  2008.  
  2009.         
  2010.     if (!get_settings('use_pingback')) {
  2011.         return new xmlrpcresp(new xmlrpcval('Sorry, this weblog does not allow you to pingback its posts.'));
  2012.     }
  2013.  
  2014.  
  2015.     //$log = debug_fopen('./xmlrpc.log', 'w');
  2016.  
  2017.     $title='';
  2018.  
  2019.     $pagelinkedfrom = $m->getParam(0);
  2020.     $pagelinkedfrom = $pagelinkedfrom->scalarval();
  2021.  
  2022.     $pagelinkedto = $m->getParam(1);
  2023.     $pagelinkedto = $pagelinkedto->scalarval();
  2024.  
  2025.     $pagelinkedfrom = str_replace('&', '&', $pagelinkedfrom);
  2026.     $pagelinkedto = preg_replace('#&([^amp\;])#is', '&$1', $pagelinkedto);
  2027.  
  2028.     //debug_fwrite($log, 'BEGIN '.time().' - '.date('Y-m-d H:i:s')."\n\n");
  2029.     //debug_fwrite($log, 'Page linked from: '.$pagelinkedfrom."\n");
  2030.     //debug_fwrite($log, 'Page linked to: '.$pagelinkedto."\n");
  2031.  
  2032.     $messages = array(
  2033.         htmlentities("Pingback from ".$pagelinkedfrom." to "
  2034.             . $pagelinkedto . " registered. Keep the web talking! :-)"),
  2035.         htmlentities("We can't find the URL to the post you are trying to "
  2036.             . "link to in your entry. Please check how you wrote the post's permalink in your entry."),
  2037.         htmlentities("We can't find the post you are trying to link to."
  2038.             . " Please check the post's permalink.")
  2039.     );
  2040.  
  2041.     $message = $messages[0];
  2042.  
  2043.     // Check if the page linked to is in our site
  2044.     $pos1 = strpos($pagelinkedto, str_replace('http://', '', str_replace('www.', '', get_settings('home'))));
  2045.     if($pos1) {
  2046.  
  2047.         // let's find which post is linked to
  2048.         $urltest = parse_url($pagelinkedto);
  2049.         if ($post_ID = url_to_postid($pagelinkedto)) {
  2050.             $way = 'url_to_postid()';
  2051.         }
  2052.         elseif (preg_match('#p/[0-9]{1,}#', $urltest['path'], $match)) {
  2053.             // the path defines the post_ID (archives/p/XXXX)
  2054.             $blah = explode('/', $match[0]);
  2055.             $post_ID = $blah[1];
  2056.             $way = 'from the path';
  2057.         } elseif (preg_match('#p=[0-9]{1,}#', $urltest['query'], $match)) {
  2058.             // the querystring defines the post_ID (?p=XXXX)
  2059.             $blah = explode('=', $match[0]);
  2060.             $post_ID = $blah[1];
  2061.             $way = 'from the querystring';
  2062.         } elseif (isset($urltest['fragment'])) {
  2063.             // an #anchor is there, it's either...
  2064.             if (intval($urltest['fragment'])) {
  2065.                 // ...an integer #XXXX (simpliest case)
  2066.                 $post_ID = $urltest['fragment'];
  2067.                 $way = 'from the fragment (numeric)';
  2068.             } elseif (preg_match('/post-[0-9]+/',$urltest['fragment'])) {
  2069.                 // ...a post id in the form 'post-###'
  2070.                 $post_ID = preg_replace('/[^0-9]+/', '', $urltest['fragment']);
  2071.                 $way = 'from the fragment (post-###)';
  2072.             } elseif (is_string($urltest['fragment'])) {
  2073.                 // ...or a string #title, a little more complicated
  2074.                 $title = preg_replace('/[^a-zA-Z0-9]/', '.', $urltest['fragment']);
  2075.                 $sql = "SELECT ID FROM $tableposts WHERE post_title RLIKE '$title'";
  2076.                 $post_ID = $wpdb->get_var($sql) or die("Query: $sql\n\nError: ");
  2077.                 $way = 'from the fragment (title)';
  2078.             }
  2079.         } else {
  2080.             // TODO: Attempt to extract a post ID from the given URL
  2081.             $post_ID = -1;
  2082.             $way = 'no match';
  2083.         }
  2084.  
  2085.         logIO("O","(PB) URI='$pagelinkedto' ID='$post_ID' Found='$way'");
  2086.  
  2087.         //debug_fwrite($log, "Found post ID $way: $post_ID\n");
  2088.  
  2089.         $sql = 'SELECT post_author FROM '.$tableposts.' WHERE ID = '.$post_ID;
  2090.         $result = $wpdb->get_results($sql);
  2091.  
  2092.         if ($wpdb->num_rows) {
  2093.  
  2094.             //debug_fwrite($log, 'Post exists'."\n");
  2095.  
  2096.             // Let's check that the remote site didn't already pingback this entry
  2097.             $sql = 'SELECT * FROM '.$tablecomments.' 
  2098.                 WHERE comment_post_ID = '.$post_ID.' 
  2099.                     AND comment_author_url = \''.$pagelinkedfrom.'\' 
  2100.                     AND comment_content LIKE \'%<pingback />%\'';
  2101.             $result = $wpdb->get_results($sql);
  2102.         
  2103.             if ($wpdb->num_rows || (1==1)) {
  2104.  
  2105.                 // very stupid, but gives time to the 'from' server to publish !
  2106.                 sleep(1);
  2107.  
  2108.                 // Let's check the remote site
  2109.                 $fp = @fopen($pagelinkedfrom, 'r');
  2110.  
  2111.                 $puntero = 4096;
  2112.                 while($remote_read = fread($fp, $puntero)) {
  2113.                     $linea .= $remote_read;
  2114.                 }
  2115.                     // Work around bug in strip_tags():
  2116.                     $linea = str_replace('<!DOCTYPE','<DOCTYPE',$linea);
  2117.                     $linea = strip_tags($linea, '<title><a>');
  2118.                     $linea = strip_all_but_one_link($linea, $pagelinkedto);
  2119.                     // I don't think we need this? -- emc3
  2120.                     //$linea = preg_replace('#&([^amp\;])#is', '&$1', $linea);
  2121.                     if (empty($matchtitle)) {
  2122.                         preg_match('|<title>([^<]*?)</title>|is', $linea, $matchtitle);
  2123.                     }
  2124.                     $pos2 = strpos($linea, $pagelinkedto);
  2125.                     $pos3 = strpos($linea, str_replace('http://www.', 'http://', $pagelinkedto));
  2126.                     if (is_integer($pos2) || is_integer($pos3)) {
  2127.                         //debug_fwrite($log, 'The page really links to us :)'."\n");
  2128.                         $pos4 = (is_integer($pos2)) ? $pos2 : $pos3;
  2129.                         $start = $pos4-100;
  2130.                         $context = substr($linea, $start, 250);
  2131.                         $context = str_replace("\n", ' ', $context);
  2132.                         $context = str_replace('&', '&', $context);
  2133.                     } else {
  2134.                         //debug_fwrite($log, 'The page doesn\'t link to us, here\'s an excerpt :'."\n\n".$linea."\n\n");
  2135.                     }
  2136.                 //}
  2137.                 //debug_fwrite($log, '*****'."\n\n");
  2138.                 fclose($fp);
  2139.  
  2140.                 if (!empty($context)) {
  2141.                     // Check if pings are on, inelegant exit
  2142.                     $pingstatus = $wpdb->get_var("SELECT ping_status FROM $tableposts WHERE ID = $post_ID");
  2143.                     if ('closed' == $pingstatus) die('Sorry, pings are turned off for this post.');
  2144.  
  2145.                     $pagelinkedfrom = preg_replace('#&([^amp\;])#is', '&$1', $pagelinkedfrom);
  2146.                     $title = (!strlen($matchtitle[1])) ? $pagelinkedfrom : $matchtitle[1];
  2147.                     $original_context = $context;
  2148.                     $context = '<pingback />[...] '.addslashes(trim($context)) .' [...]';
  2149.                     $context = format_to_post($context);
  2150.                     $original_pagelinkedfrom = $pagelinkedfrom;
  2151.                     $pagelinkedfrom = addslashes($pagelinkedfrom);
  2152.                     $original_title = $title;
  2153.                     $title = addslashes(strip_tags(trim($title)));
  2154.                     $user_ip = $_SERVER['REMOTE_ADDR'];
  2155.                     $now = gmdate('Y-m-d H:i:s');
  2156.                     if(check_comment($title, '', $pagelinkedfrom, $context, $user_ip)) {
  2157.                         $approved = 1;
  2158.                     } else {
  2159.                         $approved = 0;
  2160.                     }
  2161.                     $consulta = $wpdb->query("INSERT INTO $tablecomments 
  2162.                         (comment_post_ID, comment_author, comment_author_url, comment_author_IP, comment_date, comment_content, comment_approved) 
  2163.                         VALUES 
  2164.                         ($post_ID, '$title', '$pagelinkedfrom', '$user_ip', '$now', '$context', '$approved')
  2165.                         ");
  2166.  
  2167.                     $comment_ID = $wpdb->get_var('SELECT last_insert_id()');
  2168.                     if (get_settings('comments_notify'))
  2169.                         wp_notify_postauthor($comment_ID, 'pingback');
  2170.                     do_action('pingback_post', $comment_ID);
  2171.                 } else {
  2172.                     // URL pattern not found
  2173.                     $message = "Page linked to: $pagelinkedto\nPage linked from:"
  2174.                         . " $pagelinkedfrom\nTitle: $title\nContext: $context\n\n".$messages[1];
  2175.                 }
  2176.             } else {
  2177.                 // We already have a Pingback from this URL
  2178.                 $message = "Sorry, you already did a pingback to $pagelinkedto"
  2179.                 . " from $pagelinkedfrom.";
  2180.             }
  2181.         } else {
  2182.             // Post_ID not found
  2183.             $message = $messages[2];
  2184.             //debug_fwrite($log, 'Post doesn\'t exist'."\n");
  2185.         }
  2186.     }
  2187.     return new xmlrpcresp(new xmlrpcval($message));
  2188. }
  2189.  
  2190. /**** /PingBack functions ****/
  2191.  
  2192. /**** SERVER FUNCTIONS ARRAY ****/
  2193.  
  2194. $dispatch_map =  
  2195. array( "blogger.newPost" =>
  2196. array("function" => "bloggernewpost",
  2197.      "signature" => $bloggernewpost_sig,
  2198.      "docstring" => $bloggernewpost_doc),
  2199.  
  2200.  
  2201. "blogger.editPost" =>
  2202. array("function" => "bloggereditpost",
  2203.      "signature" => $bloggereditpost_sig,
  2204.      "docstring" => $bloggereditpost_doc),
  2205.  
  2206.  
  2207. "blogger.deletePost" =>
  2208. array("function" => "bloggerdeletepost",
  2209.      "signature" => $bloggerdeletepost_sig,
  2210.      "docstring" => $bloggerdeletepost_doc),
  2211.  
  2212.  
  2213. "blogger.getUsersBlogs" =>
  2214. array("function" => "bloggergetusersblogs",
  2215.      "signature" => $bloggergetusersblogs_sig,
  2216.      "docstring" => $bloggergetusersblogs_doc),
  2217.  
  2218. "blogger.getUserInfo" =>
  2219. array("function" => "bloggergetuserinfo",
  2220.      "signature" => $bloggergetuserinfo_sig,
  2221.      "docstring" => $bloggergetuserinfo_doc),
  2222.  
  2223. "blogger.getPost" =>
  2224. array("function" => "bloggergetpost",
  2225.      "signature" => $bloggergetpost_sig,
  2226.      "docstring" => $bloggergetpost_doc),
  2227.  
  2228. "blogger.getRecentPosts" =>
  2229. array("function" => "bloggergetrecentposts",
  2230.      "signature" => $bloggergetrecentposts_sig,
  2231.      "docstring" => $bloggergetrecentposts_doc),
  2232.  
  2233. "blogger.getTemplate" =>
  2234. array("function" => "bloggergettemplate",
  2235.      "signature" => $bloggergettemplate_sig,
  2236.      "docstring" => $bloggergettemplate_doc),
  2237.  
  2238. "blogger.setTemplate" =>
  2239. array("function" => "bloggersettemplate",
  2240.      "signature" => $bloggersettemplate_sig,
  2241.      "docstring" => $bloggersettemplate_doc),
  2242.  
  2243. "metaWeblog.newPost" =>
  2244. array("function" => "mwnewpost",
  2245.      "signature" => $mwnewpost_sig,
  2246.      "docstring" => $mwnewpost_doc),
  2247.  
  2248. "metaWeblog.editPost" =>
  2249. array("function" => "mweditpost",
  2250.      "signature" => $mweditpost_sig,
  2251.      "docstring" => $mweditpost_doc),
  2252.  
  2253. "metaWeblog.getPost" =>
  2254. array("function" => "mwgetpost",
  2255.      "signature" => $mwgetpost_sig,
  2256.      "docstring" => $mwgetpost_doc),
  2257.  
  2258. "metaWeblog.getRecentPosts" =>
  2259. array("function" => "mwrecentposts",
  2260.      "signature" => $mwrecentposts_sig,
  2261.      "docstring" => $mwrecentposts_doc),
  2262.  
  2263. "metaWeblog.getCategories" =>
  2264. array("function" => "mwgetcats",
  2265.      "signature" => $mwgetcats_sig,
  2266.      "docstring" => $mwgetcats_doc),
  2267.  
  2268. "metaWeblog.newMediaObject" =>
  2269. array("function" => "mwnewmedia",
  2270.      "signature" => $mwnewmedia_sig,
  2271.      "docstring" => $mwnewmedia_doc),
  2272.  
  2273. "mt.getCategoryList" =>
  2274. array("function" => "mwgetcats",
  2275.      "signature" => $mwgetcats_sig,
  2276.      "docstring" => $mwgetcats_doc),
  2277.  
  2278. "mt.getPostCategories" =>
  2279. array("function" => "mt_getPostCategories",
  2280.      "signature" => $mt_getPostCategories_sig,
  2281.      "docstring" => $mt_getPostCategories_doc),
  2282.  
  2283. "mt.setPostCategories" =>
  2284. array("function" => "mt_setPostCategories",
  2285.      "signature" => $mt_setPostCategories_sig,
  2286.      "docstring" => $mt_setPostCategories_doc),
  2287.  
  2288. "mt.publishPost" =>
  2289. array("function" => "mt_publishPost",
  2290.      "signature" => $mt_publishPost_sig,
  2291.      "docstring" => $mt_publishPost_doc),
  2292.  
  2293. "mt.supportedMethods" =>
  2294. array("function" => "mt_supportedMethods",
  2295.      "signature" => $mt_supportedMethods_sig,
  2296.      "docstring" => $mt_supportedMethods_doc),
  2297.  
  2298. "mt.supportedTextFilters" =>
  2299. array("function" => "mt_supportedTextFilters",
  2300.      "signature" => $mt_supportedTextFilters_sig,
  2301.      "docstring" => $mt_supportedTextFilters_doc),
  2302.  
  2303. "mt.getRecentPostTitles" =>
  2304. array("function" => "mt_getRecentPostTitles",
  2305.      "signature" => $mt_getRecentPostTitles_sig,
  2306.      "docstring" => $mt_getRecentPostTitles_doc),
  2307.  
  2308. "mt.getTrackbackPings" =>
  2309. array("function" => "mt_getTrackbackPings",
  2310.      "signature" => $mt_getTrackbackPings_sig,
  2311.      "docstring" => $mt_getTrackbackPings_doc),
  2312.  
  2313. "b2.newPost" =>
  2314. array("function" => "b2newpost",
  2315.      "signature" => $wpnewpost_sig,
  2316.      "docstring" => $wpnewpost_doc),
  2317. "b2.getCategories" =>
  2318. array("function" => "b2getcategories",
  2319.      "signature" => $wpgetcategories_sig,
  2320.      "docstring" => $wpgetcategories_doc),
  2321.  
  2322. "b2.ping" =>
  2323. array("function" => "b2ping",
  2324.      "signature" => $wpping_sig,
  2325.      "docstring" => $wpping_doc),
  2326.  
  2327. "pingback.ping" =>
  2328. array("function" => "pingback_ping",
  2329.      "signature" => $pingback_ping_sig,
  2330.      "docstring" => $pingback_ping_doc),
  2331.  
  2332. "b2.getPostURL" =>
  2333. array("function" => "pingback_getPostURL",
  2334.      "signature" => $wp_getPostURL_sig,
  2335.      "docstring" => $wp_getPostURL_doc),
  2336. );
  2337.  
  2338. $s = new xmlrpc_server($dispatch_map);
  2339.  
  2340. ?>